chore: remove some panics

It'll only error if the flag doesn't exist, which is not that bad, so
I just removed the panics for now... like the other options set the same
way.
This commit is contained in:
Carlos Alexandro Becker
2023-06-05 17:45:31 +00:00
parent 5820ab17f6
commit af65ba8a60
3 changed files with 9 additions and 16 deletions
+2 -4
View File
@@ -22,7 +22,7 @@ func newInitCmd() *initCmd {
SilenceErrors: true,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if err := os.WriteFile(root.config, []byte(example), 0o666); err != nil {
return fmt.Errorf("failed to create example file: %w", err)
}
@@ -31,9 +31,7 @@ func newInitCmd() *initCmd {
}
cmd.Flags().StringVarP(&root.config, "config", "f", "nfpm.yaml", "path to the to-be-created config file")
if err := cmd.MarkFlagFilename("config", "yaml", "yml"); err != nil {
panic(err)
}
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
root.cmd = cmd
return root
+6 -9
View File
@@ -34,17 +34,14 @@ func newPackageCmd() *packageCmd {
}
cmd.Flags().StringVarP(&root.config, "config", "f", "nfpm.yaml", "config file to be used")
if err := cmd.MarkFlagFilename("config", "yaml", "yml"); err != nil {
panic(err)
}
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
cmd.Flags().StringVarP(&root.target, "target", "t", "", "where to save the generated package (filename, folder or empty for current folder)")
if err := cmd.MarkFlagFilename("target"); err != nil {
panic(err)
}
_ = cmd.MarkFlagFilename("target")
cmd.Flags().StringVarP(&root.packager, "packager", "p", "", "which packager implementation to use [apk|deb|rpm|archlinux]")
if err := cmd.RegisterFlagCompletionFunc("packager", cobra.FixedCompletions([]string{"apk", "deb", "rpm", "archlinux"}, cobra.ShellCompDirectiveNoFileComp)); err != nil {
panic(err)
}
_ = cmd.RegisterFlagCompletionFunc("packager", cobra.FixedCompletions(
[]string{"apk", "deb", "rpm", "archlinux"},
cobra.ShellCompDirectiveNoFileComp,
))
root.cmd = cmd
return root
+1 -3
View File
@@ -48,9 +48,7 @@ func newSchemaCmd() *schemaCmd {
}
cmd.Flags().StringVarP(&root.output, "output", "o", "-", "where to save the json schema")
if err := cmd.MarkFlagFilename("output", "json"); err != nil {
panic(err)
}
_ = cmd.MarkFlagFilename("output", "json")
root.cmd = cmd
return root