Skip to content

Commit ad71af2

Browse files
committed
fix: file flag is no longer persistent
1 parent 571eed0 commit ad71af2

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

commands/copy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func cmdCopyConfig() *cobra.Command {
3434
},
3535
}
3636

37-
cmd.Flags().BoolP("force", "f", false, "overwrite existing file")
37+
cmd.Flags().BoolP("force", "F", false, "overwrite existing file")
38+
SetFileFlag(cmd)
3839

3940
return cmd
4041
}

commands/get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ func cmdGet() *cobra.Command {
3131
},
3232
}
3333

34+
SetFileFlag(cmd)
35+
3436
return cmd
3537
}

commands/init.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import (
77
func Init(rootCmd *cobra.Command) {
88
rootCmd.AddCommand(cmdGet())
99
rootCmd.AddCommand(cmdSet())
10-
rootCmd.AddCommand(cmdSetApiKey())
1110
rootCmd.AddCommand(cmdCopyConfig())
11+
rootCmd.AddCommand(cmdSetApiKey())
1212
rootCmd.AddCommand(cmdUpdate())
1313
}
14+
15+
func SetFileFlag(cmd *cobra.Command) {
16+
cmd.Flags().StringP("file", "f", "", "server config file path")
17+
cmd.MarkFlagFilename("file", "ini")
18+
cmd.MarkFlagRequired("file")
19+
}

commands/set.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func cmdSet() *cobra.Command {
6565
}
6666

6767
cmd.Flags().BoolP("no-save", "n", false, "do not save to file")
68+
SetFileFlag(cmd)
6869

6970
return cmd
7071
}

main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ pzmod --file server.ini set name "My Server"`,
3737
},
3838
}
3939

40-
rootCmd.PersistentFlags().StringP("file", "f", "", "server config file path")
41-
rootCmd.MarkPersistentFlagFilename("file", "ini")
42-
rootCmd.MarkPersistentFlagRequired("file")
43-
40+
commands.SetFileFlag(rootCmd)
4441
commands.Init(rootCmd)
4542
rootCmd.Execute()
4643
}

0 commit comments

Comments
 (0)