refactor: Make tape flag global

This commit is contained in:
Felicitas Pojtinger
2021-11-20 16:34:06 +01:00
parent fd3606ae4b
commit 1f603821aa
8 changed files with 24 additions and 10 deletions

View File

@@ -16,7 +16,6 @@ import (
)
const (
tapeFlag = "tape"
recordSizeFlag = "record-size"
srcFlag = "src"
overwriteFlag = "overwrite"
@@ -150,7 +149,6 @@ var archiveCmd = &cobra.Command{
}
func init() {
archiveCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to write to")
archiveCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
archiveCmd.PersistentFlags().StringP(srcFlag, "s", ".", "Directory to archive")
archiveCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Start writing from the current position instead of from the end of the tape/file")

View File

@@ -28,8 +28,6 @@ var ejectCmd = &cobra.Command{
}
func init() {
ejectCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape drive to get the current record from")
viper.AutomaticEnv()
rootCmd.AddCommand(ejectCmd)

View File

@@ -192,7 +192,6 @@ var listCmd = &cobra.Command{
}
func init() {
listCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to read from")
listCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
listCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too before counting")
listCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too before counting")

View File

@@ -105,7 +105,6 @@ var restoreCmd = &cobra.Command{
}
func init() {
restoreCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to read from")
restoreCmd.PersistentFlags().IntP(recordSizeFlag, "e", 20, "Amount of 512-bit blocks per record")
restoreCmd.PersistentFlags().IntP(recordFlag, "r", 0, "Record to seek too")
restoreCmd.PersistentFlags().IntP(blockFlag, "b", 0, "Block in record to seek too")

View File

@@ -7,6 +7,10 @@ import (
"github.com/spf13/viper"
)
const (
tapeFlag = "tape"
)
var rootCmd = &cobra.Command{
Use: "stbak",
Short: "Simple Tape Backup",
@@ -21,6 +25,14 @@ https://github.com/pojntfx/stfs`,
}
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)
}

View File

@@ -36,8 +36,6 @@ var tellCmd = &cobra.Command{
}
func init() {
tellCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape drive to get the current record from")
viper.AutomaticEnv()
rootCmd.AddCommand(tellCmd)

View File

@@ -16,7 +16,6 @@ import (
const (
dbFlag = "db"
tapeFlag = "tape"
recordSizeFlag = "record-size"
recordFlag = "record"
blockFlag = "block"
@@ -209,7 +208,6 @@ func init() {
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().StringP(tapeFlag, "t", "/dev/nst0", "Tape or tar file to read from")
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")

View File

@@ -7,6 +7,10 @@ import (
"github.com/spf13/viper"
)
const (
tapeFlag = "tape"
)
var rootCmd = &cobra.Command{
Use: "stcache",
Short: "Simple Tape Cache",
@@ -21,6 +25,14 @@ https://github.com/pojntfx/stfs`,
}
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)
}