Skip to content

Commit

Permalink
chore: remove some panics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
caarlos0 committed Jun 5, 2023
1 parent 5820ab1 commit af65ba8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
6 changes: 2 additions & 4 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions internal/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af65ba8

Please sign in to comment.