bind flags on pre-run rather than init

This commit is contained in:
Luke K 2020-05-25 08:44:28 +00:00
parent 032ab96787
commit 625a270942
No known key found for this signature in database
GPG Key ID: 4896F75BAF2E1966
2 changed files with 7 additions and 4 deletions

View File

@ -9,9 +9,7 @@ import (
func init() {
root.AddCommand(deleteCmd)
deleteCmd.Flags().StringP("name", "n", "", "optionally specify an explicit name to remove, overriding path-derivation. $FAAS_NAME")
viper.BindPFlag("name", deleteCmd.Flags().Lookup("name"))
}
var deleteCmd = &cobra.Command{
@ -20,6 +18,9 @@ var deleteCmd = &cobra.Command{
Long: `Removes the deployed Service Function for the current directory, but does not delete anything locally. If no code updates have been made beyond the defaults, this would bring the current codebase back to a state equivalent to having run "create --local".`,
SuggestFor: []string{"remove", "rm"},
RunE: delete,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("name", cmd.Flags().Lookup("name"))
},
}
func delete(cmd *cobra.Command, args []string) (err error) {

View File

@ -18,10 +18,8 @@ func init() {
root.AddCommand(describeCmd)
describeCmd.Flags().StringP("output", "o", "yaml", "optionally specify output format (yaml,xml,json).")
viper.BindPFlag("output", describeCmd.Flags().Lookup("output"))
describeCmd.Flags().StringP("name", "n", "", "optionally specify an explicit name for the serive, overriding path-derivation. $FAAS_NAME")
viper.BindPFlag("name", describeCmd.Flags().Lookup("name"))
}
var describeCmd = &cobra.Command{
@ -30,6 +28,10 @@ var describeCmd = &cobra.Command{
Long: `Describe Service Function`,
SuggestFor: []string{"desc"},
RunE: describe,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("output", cmd.Flags().Lookup("output"))
viper.BindPFlag("name", cmd.Flags().Lookup("name"))
},
}
func describe(cmd *cobra.Command, args []string) (err error) {