feat: Add aliases to commands, re-organize subcommands to be destinct from root commands

This commit is contained in:
Felix Pojtinger
2021-11-29 23:18:25 +01:00
parent 4a703bf1db
commit d39e4e1e92
12 changed files with 35 additions and 40 deletions

View File

@@ -25,7 +25,7 @@ const (
var archiveCmd = &cobra.Command{
Use: "archive",
Aliases: []string{"a"},
Aliases: []string{"arc", "a", "c"},
Short: "Archive a file or directory to tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {

View File

@@ -22,10 +22,10 @@ const (
nameFlag = "name"
)
var removeCmd = &cobra.Command{
Use: "remove",
Aliases: []string{"r"},
Short: "Remove a file or directory from tape or tar file",
var deleteCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"del", "d", "rm"},
Short: "Delete a file or directory from tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err
@@ -167,10 +167,10 @@ func openTapeWriter(tape string) (tw *tar.Writer, isRegular bool, cleanup func(d
}
func init() {
removeCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
removeCmd.PersistentFlags().StringP(nameFlag, "n", "", "Name of the file to remove")
deleteCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
deleteCmd.PersistentFlags().StringP(nameFlag, "n", "", "Name of the file to remove")
viper.AutomaticEnv()
rootCmd.AddCommand(removeCmd)
rootCmd.AddCommand(deleteCmd)
}

View File

@@ -10,9 +10,8 @@ import (
)
var driveEjectCmd = &cobra.Command{
Use: "eject",
Aliases: []string{"e"},
Short: "Eject tape from drive",
Use: "eject",
Short: "Eject tape from drive",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err

View File

@@ -11,9 +11,8 @@ import (
)
var driveTellCmd = &cobra.Command{
Use: "tell",
Aliases: []string{"t"},
Short: "Get the current record on the tape",
Use: "tell",
Short: "Get the current record on the tape",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err

View File

@@ -18,7 +18,7 @@ const (
var findCmd = &cobra.Command{
Use: "find",
Aliases: []string{"f"},
Aliases: []string{"fin", "f"},
Short: "Find a file or directory on tape or tar file by matching against a regex",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {

View File

@@ -13,7 +13,7 @@ import (
var listCmd = &cobra.Command{
Use: "list",
Aliases: []string{"l"},
Aliases: []string{"lis", "l", "t", "ls"},
Short: "List the contents of a directory on tape or tar file ",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {

View File

@@ -17,7 +17,7 @@ import (
var moveCmd = &cobra.Command{
Use: "move",
Aliases: []string{"m"},
Aliases: []string{"mov", "m", "mv"},
Short: "Move a file or directory on tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {

View File

@@ -21,10 +21,9 @@ const (
previewFlag = "preview"
)
var recoveryRestoreCmd = &cobra.Command{
Use: "restore",
Aliases: []string{"r"},
Short: "Restore a file or directory from tape or tar file by record and block",
var recoveryFetchCmd = &cobra.Command{
Use: "fetch",
Short: "Fetch a file or directory from tape or tar file by record and block",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err
@@ -126,13 +125,13 @@ func restoreFromRecordAndBlock(
}
func init() {
recoveryRestoreCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
recoveryRestoreCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too")
recoveryRestoreCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too")
recoveryRestoreCmd.PersistentFlags().StringP(dstFlag, "d", "", "File to restore to (archived name by default)")
recoveryRestoreCmd.PersistentFlags().BoolP(previewFlag, "p", false, "Only read the header")
recoveryFetchCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
recoveryFetchCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too")
recoveryFetchCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too")
recoveryFetchCmd.PersistentFlags().StringP(dstFlag, "d", "", "File to restore to (archived name by default)")
recoveryFetchCmd.PersistentFlags().BoolP(previewFlag, "p", false, "Only read the header")
viper.AutomaticEnv()
recoveryCmd.AddCommand(recoveryRestoreCmd)
recoveryCmd.AddCommand(recoveryFetchCmd)
}

View File

@@ -21,9 +21,8 @@ import (
)
var recoveryIndexCmd = &cobra.Command{
Use: "index",
Aliases: []string{"i"},
Short: "Index contents of tape or tar file",
Use: "index",
Short: "Index contents of tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err

View File

@@ -14,10 +14,9 @@ import (
"github.com/volatiletech/sqlboiler/v4/boil"
)
var recoveryListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"l"},
Short: "List contents of tape or tar file without the index",
var recoveryQueryCmd = &cobra.Command{
Use: "query",
Short: "Query contents of tape or tar file without the index",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err
@@ -184,11 +183,11 @@ var recoveryListCmd = &cobra.Command{
}
func init() {
recoveryListCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
recoveryListCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too before counting")
recoveryListCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too before counting")
recoveryQueryCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
recoveryQueryCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too before counting")
recoveryQueryCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too before counting")
viper.AutomaticEnv()
recoveryCmd.AddCommand(recoveryListCmd)
recoveryCmd.AddCommand(recoveryQueryCmd)
}

View File

@@ -23,7 +23,7 @@ const (
var restoreCmd = &cobra.Command{
Use: "restore",
Aliases: []string{"r"},
Aliases: []string{"res", "r", "x"},
Short: "Restore a file or directory from tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {

View File

@@ -24,7 +24,7 @@ const (
var updateCmd = &cobra.Command{
Use: "update",
Aliases: []string{"u"},
Aliases: []string{"upd", "u"},
Short: "Update a file or directory's content and metadata on tape or tar file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {