diff --git a/cmd/stcache/cmd/index.go b/cmd/stbak/cmd/index.go similarity index 92% rename from cmd/stcache/cmd/index.go rename to cmd/stbak/cmd/index.go index 06c5f4c..371adbd 100644 --- a/cmd/stcache/cmd/index.go +++ b/cmd/stbak/cmd/index.go @@ -7,7 +7,6 @@ import ( "io" "math" "os" - "path/filepath" "github.com/pojntfx/stfs/pkg/controllers" "github.com/pojntfx/stfs/pkg/formatting" @@ -17,14 +16,6 @@ import ( "github.com/spf13/viper" ) -const ( - dbFlag = "db" - recordSizeFlag = "record-size" - recordFlag = "record" - blockFlag = "block" - overwriteFlag = "overwrite" -) - var indexCmd = &cobra.Command{ Use: "index", Aliases: []string{"i"}, @@ -232,14 +223,6 @@ var indexCmd = &cobra.Command{ } func init() { - // Get default working dir - home, err := os.UserHomeDir() - if err != nil { - panic(err) - } - workingDirDefault := filepath.Join(home, ".local", "share", "stcache", "var", "lib", "stcache") - - indexCmd.PersistentFlags().StringP(dbFlag, "d", filepath.Join(workingDirDefault, "index.sqlite"), "Database to use") indexCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record") indexCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too before counting") indexCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too before counting") diff --git a/cmd/stcache/cmd/list.go b/cmd/stbak/cmd/query.go similarity index 77% rename from cmd/stcache/cmd/list.go rename to cmd/stbak/cmd/query.go index a6453da..103dd03 100644 --- a/cmd/stcache/cmd/list.go +++ b/cmd/stbak/cmd/query.go @@ -4,8 +4,6 @@ import ( "archive/tar" "context" "encoding/json" - "os" - "path/filepath" "github.com/pojntfx/stfs/pkg/formatting" "github.com/pojntfx/stfs/pkg/persisters" @@ -13,10 +11,10 @@ import ( "github.com/spf13/viper" ) -var list = &cobra.Command{ - Use: "list", - Aliases: []string{"l"}, - Short: "List contents of index", +var queryCmd = &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Query the contents of an index", RunE: func(cmd *cobra.Command, args []string) error { if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil { return err @@ -71,16 +69,7 @@ var list = &cobra.Command{ } func init() { - // Get default working dir - home, err := os.UserHomeDir() - if err != nil { - panic(err) - } - workingDirDefault := filepath.Join(home, ".local", "share", "stcache", "var", "lib", "stcache") - - list.PersistentFlags().StringP(dbFlag, "d", filepath.Join(workingDirDefault, "index.sqlite"), "Database to use") - viper.AutomaticEnv() - rootCmd.AddCommand(list) + rootCmd.AddCommand(queryCmd) } diff --git a/cmd/stbak/cmd/root.go b/cmd/stbak/cmd/root.go index 9f8e985..e111c9a 100644 --- a/cmd/stbak/cmd/root.go +++ b/cmd/stbak/cmd/root.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "path/filepath" "strings" "github.com/spf13/cobra" @@ -9,12 +11,13 @@ import ( const ( tapeFlag = "tape" + dbFlag = "db" ) var rootCmd = &cobra.Command{ Use: "stbak", Short: "Simple Tape Backup", - Long: `Simple Tape Backup (stbak) is a CLI to interact with STFS-managed tapes or tar files. + Long: `Simple Tape Backup (stbak) is a CLI to interact with STFS-managed tapes, tar files and indexes. Find more information at: https://github.com/pojntfx/stfs`, @@ -25,7 +28,15 @@ https://github.com/pojntfx/stfs`, } func Execute() { + // Get default working dir + home, err := os.UserHomeDir() + if err != nil { + panic(err) + } + workingDirDefault := filepath.Join(home, ".local", "share", "stcache", "var", "lib", "stcache") + rootCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to use") + rootCmd.PersistentFlags().StringP(dbFlag, "d", filepath.Join(workingDirDefault, "index.sqlite"), "Database to use") if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { panic(err) diff --git a/cmd/stcache/cmd/root.go b/cmd/stcache/cmd/root.go deleted file mode 100644 index 11d79d8..0000000 --- a/cmd/stcache/cmd/root.go +++ /dev/null @@ -1,39 +0,0 @@ -package cmd - -import ( - "strings" - - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -const ( - tapeFlag = "tape" -) - -var rootCmd = &cobra.Command{ - Use: "stcache", - Short: "Simple Tape Cache", - Long: `Simple Tape Cache (stcache) is a CLI to interact with STFS-managed indexes of tapes or tar files. - -Find more information at: -https://github.com/pojntfx/stfs`, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - viper.SetEnvPrefix("stcache") - viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) - }, -} - -func Execute() { - rootCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to use") - - if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { - panic(err) - } - - viper.AutomaticEnv() - - if err := rootCmd.Execute(); err != nil { - panic(err) - } -} diff --git a/cmd/stcache/main.go b/cmd/stcache/main.go deleted file mode 100644 index 567c8cc..0000000 --- a/cmd/stcache/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/pojntfx/stfs/cmd/stcache/cmd" - -func main() { - cmd.Execute() -}