Skip to content

Commit

Permalink
fix: file flag is no longer persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
kldzj committed May 7, 2023
1 parent 571eed0 commit ad71af2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion commands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func cmdCopyConfig() *cobra.Command {
},
}

cmd.Flags().BoolP("force", "f", false, "overwrite existing file")
cmd.Flags().BoolP("force", "F", false, "overwrite existing file")
SetFileFlag(cmd)

return cmd
}
2 changes: 2 additions & 0 deletions commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ func cmdGet() *cobra.Command {
},
}

SetFileFlag(cmd)

return cmd
}
8 changes: 7 additions & 1 deletion commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import (
func Init(rootCmd *cobra.Command) {
rootCmd.AddCommand(cmdGet())
rootCmd.AddCommand(cmdSet())
rootCmd.AddCommand(cmdSetApiKey())
rootCmd.AddCommand(cmdCopyConfig())
rootCmd.AddCommand(cmdSetApiKey())
rootCmd.AddCommand(cmdUpdate())
}

func SetFileFlag(cmd *cobra.Command) {
cmd.Flags().StringP("file", "f", "", "server config file path")
cmd.MarkFlagFilename("file", "ini")
cmd.MarkFlagRequired("file")
}
1 change: 1 addition & 0 deletions commands/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func cmdSet() *cobra.Command {
}

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

return cmd
}
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ pzmod --file server.ini set name "My Server"`,
},
}

rootCmd.PersistentFlags().StringP("file", "f", "", "server config file path")
rootCmd.MarkPersistentFlagFilename("file", "ini")
rootCmd.MarkPersistentFlagRequired("file")

commands.SetFileFlag(rootCmd)
commands.Init(rootCmd)
rootCmd.Execute()
}

0 comments on commit ad71af2

Please sign in to comment.