refactor: Move drive and recovery commands to subcommands

This commit is contained in:
Felicitas Pojtinger
2021-11-28 19:07:10 +01:00
parent 05d4ef999a
commit 35a447a9cc
11 changed files with 44 additions and 10 deletions

View File

@@ -208,7 +208,7 @@ func archive(
func init() {
archiveCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
archiveCmd.PersistentFlags().StringP(srcFlag, "s", ".", "File or directory to archive")
archiveCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Start writing from the start instead of from the end of the tape/file")
archiveCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Start writing from the start instead of from the end of the tape or tar file")
viper.AutomaticEnv()

View File

@@ -35,5 +35,5 @@ var ejectCmd = &cobra.Command{
func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(ejectCmd)
driveCmd.AddCommand(ejectCmd)
}

View File

@@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var driveCmd = &cobra.Command{
Use: "drive",
Short: "Manage tape drives",
}
func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(driveCmd)
}

View File

@@ -43,5 +43,5 @@ var tellCmd = &cobra.Command{
func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(tellCmd)
driveCmd.AddCommand(tellCmd)
}

View File

@@ -66,7 +66,7 @@ var moveCmd = &cobra.Command{
return err
}
// Append move headers to the tape/tar file
// Append move headers to the tape or tar file
for _, dbhdr := range headersToMove {
hdr, err := converters.DBHeaderToTarHeader(dbhdr)
if err != nil {

View File

@@ -219,11 +219,11 @@ func init() {
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")
indexCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Start writing from the current position instead of from the end of the tape/file")
indexCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Remove the old index before starting to index")
viper.AutomaticEnv()
rootCmd.AddCommand(indexCmd)
recoveryCmd.AddCommand(indexCmd)
}
func indexHeader(record, block int64, hdr *tar.Header, metadataPersister *persisters.MetadataPersister) error {

View File

@@ -190,5 +190,5 @@ func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(listCmd)
recoveryCmd.AddCommand(listCmd)
}

View File

@@ -113,5 +113,5 @@ func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(restoreCmd)
recoveryCmd.AddCommand(restoreCmd)
}

View File

@@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var recoveryCmd = &cobra.Command{
Use: "recovery",
Short: "Recover tapes or tar files",
}
func init() {
viper.AutomaticEnv()
rootCmd.AddCommand(recoveryCmd)
}

View File

@@ -73,7 +73,7 @@ var removeCmd = &cobra.Command{
return err
}
// Append deletion headers to the tape/tar file
// Append deletion headers to the tape or tar file
for _, dbhdr := range headersToDelete {
hdr, err := converters.DBHeaderToTarHeader(dbhdr)
if err != nil {

View File

@@ -168,7 +168,7 @@ func update(
func init() {
updateCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
updateCmd.PersistentFlags().StringP(srcFlag, "s", "", "Path of the file or directory to update")
updateCmd.PersistentFlags().BoolP(contentFlag, "c", false, "Replace the content on the tape/tar file")
updateCmd.PersistentFlags().BoolP(contentFlag, "c", false, "Replace the content on the tape or tar file")
viper.AutomaticEnv()