Skip to content

Commit

Permalink
adds staging a file
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Jun 29, 2018
1 parent f4822cc commit a6cfce9
Show file tree
Hide file tree
Showing 44 changed files with 1,161 additions and 377 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ tags
/.idea/
/.vscode/
*.iml
data/

# Trumpet related settings
.trumpet
12 changes: 3 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
[[constraint]]
name = "github.com/teris-io/shortid"
version = "1.0.0"

[[constraint]]
name = "github.com/djherbis/times"
version = "1.0.1"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ To enable fast access to files in a geographical location we run a sync server w
### Archiving

Once we detect files are no longer in use and have gone stale after some configurable amount of time we move these files to cold storage (glacier).
To detect files that are in use we inspect all the inputs of the runs
To detect files that are in use we inspect all the inputs of the runs and find all the commit ids for a given data repository that no longer occur.

### Execution

Expand Down
19 changes: 6 additions & 13 deletions cmd/tpt/cmd/bundle.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
// Copyright © 2018 One Concern


package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// bundleCmd represents the bundle command
var bundleCmd = &cobra.Command{
Use: "bundle",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("bundle called")
},
Short: "Commands to manage bundles for a repo",
Long: `Commands to manage bundles for a repo.
A bundle is a group of files that were changed together.
Every bundle is an entry in the history of a repository.
`,
}

func init() {
Expand Down
61 changes: 61 additions & 0 deletions cmd/tpt/cmd/bundle_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright © 2018 One Concern

package cmd

import (
"log"
"path/filepath"

"github.com/oneconcern/trumpet"
"github.com/spf13/cobra"
)

// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add",
Short: "Add a file to a bundle for commit",
Long: `Add a file or group of files to a bundle for commit.
This command supports providing one or more glob patterns
`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
tpt, err := trumpet.New("")
if err != nil {
log.Fatalln(err)
}

repo, err := tpt.GetRepo("hello-there")
if err != nil {
log.Fatalln(err)
}

for _, arg := range args {
pths, err := filepath.Glob(arg)
if err != nil {
log.Fatalln(err)
}
for _, pth := range pths {
addBlob, err := trumpet.UnstagedFilePath(pth)
if err != nil {
log.Fatalln(err)
}

hash, isNew, err := repo.Stage().Add(addBlob)
if err != nil {
log.Fatalln(err)
}

log.Println("added file", hash, "is new:", isNew)
}
}
},
}

func init() {
bundleCmd.AddCommand(addCmd)
for i := 1; i < 100; i++ {
addCmd.MarkZshCompPositionalArgumentFile(i, "*")
}
addRepoNameOption(addCmd)
}
13 changes: 6 additions & 7 deletions cmd/tpt/cmd/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd
import (
"fmt"
"log"
"runtime"

"github.com/oneconcern/trumpet/pkg/cflags"
"github.com/oneconcern/trumpet/pkg/fingerprint"
Expand All @@ -24,13 +23,13 @@ var checksumCmd = &cobra.Command{
Use: "checksum",
Short: "Create a blake2b checksum for a file or a tree of files",
Long: ``,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
maker := &fingerprint.Maker{
Size: uint8(int64(checksumOpts.Size)),
LeafSize: uint32(checksumOpts.LeafSize),
NumberOfWorkers: runtime.NumCPU(),
}
fp, err := maker.Process(args[0])
fp, err := fingerprint.New(
fingerprint.Size(uint8(int64(checksumOpts.Size))),
fingerprint.LeafSize(int64(checksumOpts.LeafSize)),
).Process(args[0])

if err != nil {
log.Fatalln(err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/tpt/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var completionCmd = &cobra.Command{
`,
ValidArgs: []string{"bash", "zsh"},
Args: cobra.OnlyValidArgs,

Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
// #nosec
Expand Down
37 changes: 37 additions & 0 deletions cmd/tpt/cmd/file_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2018 One Concern

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// fileAddCmd represents the add command
var fileAddCmd = &cobra.Command{
Use: "add",
Short: "Add a file to upload",
Long: `Add a file to the stage of a bundle, this does not yet upload the file.
This operation adds the file to be uploaded. At this stage we create a fingerprint for this file.
The file will be copied to a deduplicated staging area with its hash as name
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("add called")
},
}

func init() {
fileCmd.AddCommand(fileAddCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// fileAddCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// fileAddCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
14 changes: 1 addition & 13 deletions cmd/tpt/cmd/repo.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// Copyright © 2018 One Concern


package cmd

import (
"github.com/spf13/cobra"
)

var repoOptions struct {
Name string
Name string
Description string
}



// repoCmd represents the repo command
var repoCmd = &cobra.Command{
Use: "repo",
Expand All @@ -27,15 +24,6 @@ Repositories don't carry much content until a commit is made.
func init() {
rootCmd.AddCommand(repoCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// repoCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// repoCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func addRepoOptions(cmd *cobra.Command) error {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 13 additions & 10 deletions cmd/tpt/cmd/repo_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/oneconcern/trumpet/pkg/store/localfs"
"log"

"github.com/oneconcern/trumpet"
"github.com/oneconcern/trumpet/pkg/store"
"github.com/spf13/cobra"
)

// createCmd represents the create command
Expand All @@ -18,19 +19,21 @@ var createCmd = &cobra.Command{
The description field can use markdown formatting.`,

Run: func(cmd *cobra.Command, args []string) {
repodb := localfs.New()
if err := repodb.Initialize(); err != nil {
tpt, err := trumpet.New("")
if err != nil {
log.Fatalln(err)
}

var repo store.Repo
repo.Name = repoOptions.Name
repo.Description = repoOptions.Description

if err := repodb.Create(&repo); err != nil && err != localfs.RepoAlreadyExists {
repo, err := tpt.CreateRepo(repoOptions.Name, repoOptions.Description)
if err != nil && err != store.RepoAlreadyExists {
log.Fatalln(err)
}
log.Printf("%s has been created", repoOptions.Name)

if err == store.RepoAlreadyExists {
log.Printf("%s already existed, no action taken", repo.Name)
} else {
log.Printf("%s has been created", repo.Name)
}
},
}

Expand Down
19 changes: 10 additions & 9 deletions cmd/tpt/cmd/repo_delete.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// Copyright © 2018 One Concern


package cmd

import (
"github.com/spf13/cobra"
"github.com/oneconcern/trumpet/pkg/store/localfs"
"log"

"github.com/oneconcern/trumpet"
"github.com/spf13/cobra"
)

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a data repository",
Long: `Delete a data repository. This will only succeed when the repository is an orphan`,
Use: "delete",
Short: "Delete a data repository",
Long: `Delete a data repository. This will only succeed when the repository is an orphan`,
Aliases: []string{"del", "rm"},
Run: func(cmd *cobra.Command, args []string) {
repodb := localfs.New()
if err := repodb.Initialize(); err != nil {
tpt, err := trumpet.New("")
if err != nil {
log.Fatalln(err)
}

if err := repodb.Delete(repoOptions.Name); err != nil {
if err := tpt.DeleteRepo(repoOptions.Name); err != nil {
log.Fatalln(err)
}
log.Printf("%s has been deleted", repoOptions.Name)
Expand Down
Loading

0 comments on commit a6cfce9

Please sign in to comment.