diff --git a/cmd/config/config.go b/cmd/config/config.go index 6c212d1cf9..d038c316f5 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -9,7 +9,7 @@ import ( "github.com/flyteorg/flytectl/pkg/printer" ) -//go:generate pflags Config +//go:generate pflags Config --bind-default-var var ( defaultConfig = &Config{} diff --git a/cmd/config/config_flags.go b/cmd/config/config_flags.go index 3a1616b7e6..f219394ffb 100755 --- a/cmd/config/config_flags.go +++ b/cmd/config/config_flags.go @@ -50,8 +50,8 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.String(fmt.Sprintf("%v%v", prefix, "project"), defaultConfig.Project, "Specifies the project to work on.") - cmdFlags.String(fmt.Sprintf("%v%v", prefix, "domain"), defaultConfig.Domain, "Specified the domain to work on.") - cmdFlags.String(fmt.Sprintf("%v%v", prefix, "output"), defaultConfig.Output, "Specified the output type.") + cmdFlags.StringVar(&defaultConfig.Project, fmt.Sprintf("%v%v", prefix, "project"), defaultConfig.Project, "Specifies the project to work on.") + cmdFlags.StringVar(&defaultConfig.Domain, fmt.Sprintf("%v%v", prefix, "domain"), defaultConfig.Domain, "Specified the domain to work on.") + cmdFlags.StringVar(&defaultConfig.Output, fmt.Sprintf("%v%v", prefix, "output"), defaultConfig.Output, "Specified the output type.") return cmdFlags } diff --git a/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go b/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go index 2ee35a7887..447d2e0471 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go @@ -28,6 +28,15 @@ func (AttrDeleteConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrDeleteConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrDeleteConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrDeleteConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultDelConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") + cmdFlags.StringVar(&DefaultDelConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go b/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go index 798e81d2cf..63cb34732b 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrDeleteConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(val, result)) } -func testDecodeSlice_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrDeleteConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultDelConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go b/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go index 477e57689f..47dfb88623 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go @@ -28,6 +28,15 @@ func (AttrFetchConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrFetchConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrFetchConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrFetchConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultFetchConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") + cmdFlags.StringVar(&DefaultFetchConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go b/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go index 4d8ae3e0e6..dbcbb814fb 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrFetchConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(val, result)) } -func testDecodeSlice_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrFetchConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultFetchConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go b/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go index 60a9af145a..7b19fc93f4 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go @@ -28,6 +28,15 @@ func (AttrUpdateConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrUpdateConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrUpdateConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrUpdateConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultUpdateConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") + cmdFlags.StringVar(&DefaultUpdateConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go b/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go index aa5d18dd07..9856912248 100755 --- a/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go +++ b/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrUpdateConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(val, result)) } -func testDecodeSlice_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrUpdateConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultUpdateConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/clusterresourceattribute/delete_config.go b/cmd/config/subcommand/clusterresourceattribute/delete_config.go index 3b81cd0991..1112003923 100644 --- a/cmd/config/subcommand/clusterresourceattribute/delete_config.go +++ b/cmd/config/subcommand/clusterresourceattribute/delete_config.go @@ -1,6 +1,6 @@ package clusterresourceattribute -//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig +//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig --bind-default-var // AttrDeleteConfig Matchable resource attributes configuration passed from command line type AttrDeleteConfig struct { diff --git a/cmd/config/subcommand/clusterresourceattribute/fetch_config.go b/cmd/config/subcommand/clusterresourceattribute/fetch_config.go index 9da6d481f8..88afae90ac 100644 --- a/cmd/config/subcommand/clusterresourceattribute/fetch_config.go +++ b/cmd/config/subcommand/clusterresourceattribute/fetch_config.go @@ -1,6 +1,6 @@ package clusterresourceattribute -//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig +//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig --bind-default-var type AttrFetchConfig struct { AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` diff --git a/cmd/config/subcommand/clusterresourceattribute/update_config.go b/cmd/config/subcommand/clusterresourceattribute/update_config.go index 2ff214af1f..fcbbe04d2a 100644 --- a/cmd/config/subcommand/clusterresourceattribute/update_config.go +++ b/cmd/config/subcommand/clusterresourceattribute/update_config.go @@ -1,6 +1,6 @@ package clusterresourceattribute -//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig +//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig --bind-default-var // AttrUpdateConfig Matchable resource attributes configuration passed from command line type AttrUpdateConfig struct { diff --git a/cmd/config/subcommand/execution/config_flags.go b/cmd/config/subcommand/execution/config_flags.go index 467fbd7f6c..f9a96f5261 100755 --- a/cmd/config/subcommand/execution/config_flags.go +++ b/cmd/config/subcommand/execution/config_flags.go @@ -50,8 +50,8 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.field-selector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") - cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sort-by"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") + cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.fieldSelector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") + cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") cmdFlags.BoolVar(&DefaultConfig.Details, fmt.Sprintf("%v%v", prefix, "details"), DefaultConfig.Details, "gets node execution details. Only applicable for single execution name i.e get execution name --details") diff --git a/cmd/config/subcommand/execution/config_flags_test.go b/cmd/config/subcommand/execution/config_flags_test.go index 7fbd9e51f7..88cfd5fca0 100755 --- a/cmd/config/subcommand/execution/config_flags_test.go +++ b/cmd/config/subcommand/execution/config_flags_test.go @@ -99,13 +99,13 @@ func TestConfig_SetFlags(t *testing.T) { cmdFlags := actual.GetPFlagSet("") assert.True(t, cmdFlags.HasFlags()) - t.Run("Test_filter.field-selector", func(t *testing.T) { + t.Run("Test_filter.fieldSelector", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.field-selector", testValue) - if vString, err := cmdFlags.GetString("filter.field-selector"); err == nil { + cmdFlags.Set("filter.fieldSelector", testValue) + if vString, err := cmdFlags.GetString("filter.fieldSelector"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.FieldSelector) } else { @@ -113,13 +113,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.sort-by", func(t *testing.T) { + t.Run("Test_filter.sortBy", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.sort-by", testValue) - if vString, err := cmdFlags.GetString("filter.sort-by"); err == nil { + cmdFlags.Set("filter.sortBy", testValue) + if vString, err := cmdFlags.GetString("filter.sortBy"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.SortBy) } else { diff --git a/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go b/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go index 3dc56c9837..bbaa014f79 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go +++ b/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go @@ -28,6 +28,15 @@ func (AttrDeleteConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrDeleteConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrDeleteConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrDeleteConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultDelConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") + cmdFlags.StringVar(&DefaultDelConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go b/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go index 02ec1217d1..2c669643d9 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go +++ b/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrDeleteConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(val, result)) } -func testDecodeSlice_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrDeleteConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultDelConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go b/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go index 0e1d0d060f..97bf9e8ff1 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go +++ b/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go @@ -28,6 +28,15 @@ func (AttrFetchConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrFetchConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrFetchConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrFetchConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultFetchConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") + cmdFlags.StringVar(&DefaultFetchConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go b/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go index a99fd91933..495e5024d6 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go +++ b/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrFetchConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(val, result)) } -func testDecodeSlice_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrFetchConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultFetchConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go b/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go index f2f0d84852..bb592423db 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go +++ b/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go @@ -28,6 +28,15 @@ func (AttrUpdateConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrUpdateConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrUpdateConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrUpdateConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultUpdateConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") + cmdFlags.StringVar(&DefaultUpdateConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go b/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go index ca7e09eb4d..fa011c6c1b 100755 --- a/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go +++ b/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrUpdateConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(val, result)) } -func testDecodeSlice_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrUpdateConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultUpdateConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionclusterlabel/delete_config.go b/cmd/config/subcommand/executionclusterlabel/delete_config.go index 5a96d6fdfa..cbd1a09018 100644 --- a/cmd/config/subcommand/executionclusterlabel/delete_config.go +++ b/cmd/config/subcommand/executionclusterlabel/delete_config.go @@ -1,6 +1,6 @@ package executionclusterlabel -//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig +//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig --bind-default-var // AttrDeleteConfig Matchable resource attributes configuration passed from command line type AttrDeleteConfig struct { diff --git a/cmd/config/subcommand/executionclusterlabel/fetch_config.go b/cmd/config/subcommand/executionclusterlabel/fetch_config.go index 8e7f878ede..68a27ea6fb 100644 --- a/cmd/config/subcommand/executionclusterlabel/fetch_config.go +++ b/cmd/config/subcommand/executionclusterlabel/fetch_config.go @@ -1,6 +1,6 @@ package executionclusterlabel -//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig +//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig --bind-default-var type AttrFetchConfig struct { AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` diff --git a/cmd/config/subcommand/executionclusterlabel/update_config.go b/cmd/config/subcommand/executionclusterlabel/update_config.go index abd5600553..ba3e9d3d88 100644 --- a/cmd/config/subcommand/executionclusterlabel/update_config.go +++ b/cmd/config/subcommand/executionclusterlabel/update_config.go @@ -1,6 +1,6 @@ package executionclusterlabel -//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig +//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig --bind-default-var // AttrUpdateConfig Matchable resource attributes configuration passed from command line type AttrUpdateConfig struct { diff --git a/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go b/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go index 15852717de..d3ab937c61 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go +++ b/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go @@ -28,6 +28,15 @@ func (AttrDeleteConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrDeleteConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrDeleteConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrDeleteConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultDelConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") + cmdFlags.StringVar(&DefaultDelConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go b/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go index d42fa0c9c7..46875fd457 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go +++ b/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrDeleteConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(val, result)) } -func testDecodeSlice_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrDeleteConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultDelConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go b/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go index 0eed381d70..05a277f93a 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go +++ b/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go @@ -28,6 +28,15 @@ func (AttrFetchConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrFetchConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrFetchConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrFetchConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultFetchConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") + cmdFlags.StringVar(&DefaultFetchConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go b/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go index 449b82faae..73e37ab447 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go +++ b/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrFetchConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(val, result)) } -func testDecodeSlice_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrFetchConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultFetchConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go b/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go index c858ca34c8..ffd725ff3e 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go +++ b/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go @@ -28,6 +28,15 @@ func (AttrUpdateConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrUpdateConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrUpdateConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrUpdateConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultUpdateConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") + cmdFlags.StringVar(&DefaultUpdateConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go b/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go index dbe6642165..fafee300fb 100755 --- a/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go +++ b/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrUpdateConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(val, result)) } -func testDecodeSlice_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrUpdateConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultUpdateConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/executionqueueattribute/delete_config.go b/cmd/config/subcommand/executionqueueattribute/delete_config.go index a6754eb4f4..48dedc581b 100644 --- a/cmd/config/subcommand/executionqueueattribute/delete_config.go +++ b/cmd/config/subcommand/executionqueueattribute/delete_config.go @@ -1,6 +1,6 @@ package executionqueueattribute -//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig +//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig --bind-default-var // AttrDeleteConfig Matchable resource attributes configuration passed from command line type AttrDeleteConfig struct { diff --git a/cmd/config/subcommand/executionqueueattribute/fetch_config.go b/cmd/config/subcommand/executionqueueattribute/fetch_config.go index 4c5c154f2b..62a76d6ba1 100644 --- a/cmd/config/subcommand/executionqueueattribute/fetch_config.go +++ b/cmd/config/subcommand/executionqueueattribute/fetch_config.go @@ -1,6 +1,6 @@ package executionqueueattribute -//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig +//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig --bind-default-var type AttrFetchConfig struct { AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` diff --git a/cmd/config/subcommand/executionqueueattribute/update_config.go b/cmd/config/subcommand/executionqueueattribute/update_config.go index 11b319f1d1..8dd3e595a4 100644 --- a/cmd/config/subcommand/executionqueueattribute/update_config.go +++ b/cmd/config/subcommand/executionqueueattribute/update_config.go @@ -1,6 +1,6 @@ package executionqueueattribute -//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig +//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig --bind-default-var // AttrUpdateConfig Matchable resource attributes configuration passed from command line type AttrUpdateConfig struct { diff --git a/cmd/config/subcommand/launchplan/config_flags.go b/cmd/config/subcommand/launchplan/config_flags.go index db572d98ea..e41777eebc 100755 --- a/cmd/config/subcommand/launchplan/config_flags.go +++ b/cmd/config/subcommand/launchplan/config_flags.go @@ -50,13 +50,12 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultConfig.ExecFile), fmt.Sprintf("%v%v", prefix, "execFile"), DefaultConfig.ExecFile, "execution file name to be used for generating execution spec of a single launchplan.") - cmdFlags.StringVar(&(DefaultConfig.Version), fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "version of the launchplan to be fetched.") - cmdFlags.BoolVar(&(DefaultConfig.Latest), fmt.Sprintf("%v%v", prefix, "latest"), DefaultConfig.Latest, "flag to indicate to fetch the latest version, version flag will be ignored in this case") - - cmdFlags.StringVar(&(DefaultConfig.Filter.FieldSelector), fmt.Sprintf("%v%v", prefix, "filter.field-selector"), *new(string), "Specifies the Field selector") - cmdFlags.StringVar((&DefaultConfig.Filter.SortBy), fmt.Sprintf("%v%v", prefix, "filter.sort-by"), *new(string), "Specifies which field to sort result by ") - cmdFlags.Int32Var((&DefaultConfig.Filter.Limit), fmt.Sprintf("%v%v", prefix, "filter.limit"), 100, "Specifies the limit") - cmdFlags.BoolVar((&DefaultConfig.Filter.Asc), fmt.Sprintf("%v%v", prefix, "filter.asc"), false, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.StringVar(&DefaultConfig.ExecFile, fmt.Sprintf("%v%v", prefix, "execFile"), DefaultConfig.ExecFile, "execution file name to be used for generating execution spec of a single launchplan.") + cmdFlags.StringVar(&DefaultConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "version of the launchplan to be fetched.") + cmdFlags.BoolVar(&DefaultConfig.Latest, fmt.Sprintf("%v%v", prefix, "latest"), DefaultConfig.Latest, " flag to indicate to fetch the latest version, version flag will be ignored in this case") + cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.fieldSelector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") + cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") + cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") + cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") return cmdFlags } diff --git a/cmd/config/subcommand/launchplan/config_flags_test.go b/cmd/config/subcommand/launchplan/config_flags_test.go index ec536464bc..d2ccb2715d 100755 --- a/cmd/config/subcommand/launchplan/config_flags_test.go +++ b/cmd/config/subcommand/launchplan/config_flags_test.go @@ -141,13 +141,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.field-selector", func(t *testing.T) { + t.Run("Test_filter.fieldSelector", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.field-selector", testValue) - if vString, err := cmdFlags.GetString("filter.field-selector"); err == nil { + cmdFlags.Set("filter.fieldSelector", testValue) + if vString, err := cmdFlags.GetString("filter.fieldSelector"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.FieldSelector) } else { @@ -155,13 +155,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.sort-by", func(t *testing.T) { + t.Run("Test_filter.sortBy", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.sort-by", testValue) - if vString, err := cmdFlags.GetString("filter.sort-by"); err == nil { + cmdFlags.Set("filter.sortBy", testValue) + if vString, err := cmdFlags.GetString("filter.sortBy"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.SortBy) } else { diff --git a/cmd/config/subcommand/launchplan/launchplan_config.go b/cmd/config/subcommand/launchplan/launchplan_config.go index 5e245deb48..7c8245256a 100644 --- a/cmd/config/subcommand/launchplan/launchplan_config.go +++ b/cmd/config/subcommand/launchplan/launchplan_config.go @@ -4,7 +4,7 @@ import ( "github.com/flyteorg/flytectl/pkg/filters" ) -//go:generate pflags Config --default-var DefaultConfig +//go:generate pflags Config --default-var DefaultConfig --bind-default-var var ( DefaultConfig = &Config{ Filter: filters.DefaultFilter, diff --git a/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go b/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go index 52fd144b99..7003e5e1dd 100755 --- a/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go +++ b/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go @@ -28,6 +28,15 @@ func (AttrDeleteConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrDeleteConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrDeleteConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrDeleteConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultDelConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") + cmdFlags.StringVar(&DefaultDelConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go b/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go index 7a5d60873c..0129073516 100755 --- a/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go +++ b/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrDeleteConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(val, result)) } -func testDecodeSlice_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrDeleteConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultDelConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go b/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go index 1cf522b3ca..e7c79a92b4 100755 --- a/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go +++ b/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go @@ -28,6 +28,15 @@ func (AttrFetchConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrFetchConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrFetchConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrFetchConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultFetchConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") + cmdFlags.StringVar(&DefaultFetchConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go b/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go index e94f54e982..d5206f1d33 100755 --- a/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go +++ b/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrFetchConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(val, result)) } -func testDecodeSlice_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrFetchConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultFetchConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go b/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go index 21c58dbb9d..1edf682879 100755 --- a/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go +++ b/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go @@ -28,6 +28,15 @@ func (AttrUpdateConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrUpdateConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrUpdateConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrUpdateConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultUpdateConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") + cmdFlags.StringVar(&DefaultUpdateConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go b/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go index 37ee0382c1..c23184f43b 100755 --- a/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go +++ b/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrUpdateConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(val, result)) } -func testDecodeSlice_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrUpdateConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultUpdateConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/plugin_override/delete_config.go b/cmd/config/subcommand/plugin_override/delete_config.go index beec54fd95..de00f5cf7f 100644 --- a/cmd/config/subcommand/plugin_override/delete_config.go +++ b/cmd/config/subcommand/plugin_override/delete_config.go @@ -1,6 +1,6 @@ package pluginoverride -//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig +//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig --bind-default-var // AttrDeleteConfig Matchable resource attributes configuration passed from command line type AttrDeleteConfig struct { diff --git a/cmd/config/subcommand/plugin_override/fetch_config.go b/cmd/config/subcommand/plugin_override/fetch_config.go index 9976d8b33f..e2283e7c80 100644 --- a/cmd/config/subcommand/plugin_override/fetch_config.go +++ b/cmd/config/subcommand/plugin_override/fetch_config.go @@ -1,6 +1,6 @@ package pluginoverride -//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig +//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig --bind-default-var type AttrFetchConfig struct { AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` diff --git a/cmd/config/subcommand/plugin_override/update_config.go b/cmd/config/subcommand/plugin_override/update_config.go index e2daefa8f3..aa0d9af0b2 100644 --- a/cmd/config/subcommand/plugin_override/update_config.go +++ b/cmd/config/subcommand/plugin_override/update_config.go @@ -1,6 +1,6 @@ package pluginoverride -//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig +//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig --bind-default-var // AttrUpdateConfig Matchable resource attributes configuration passed from command line type AttrUpdateConfig struct { diff --git a/cmd/config/subcommand/project/config_flags.go b/cmd/config/subcommand/project/config_flags.go index 3a3e9bb5df..ca18dca630 100755 --- a/cmd/config/subcommand/project/config_flags.go +++ b/cmd/config/subcommand/project/config_flags.go @@ -50,9 +50,9 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultConfig.Filter.FieldSelector), fmt.Sprintf("%v%v", prefix, "filter.field-selector"), *new(string), "Specifies the Field selector") - cmdFlags.StringVar((&DefaultConfig.Filter.SortBy), fmt.Sprintf("%v%v", prefix, "filter.sort-by"), *new(string), "Specifies which field to sort result by ") - cmdFlags.Int32Var((&DefaultConfig.Filter.Limit), fmt.Sprintf("%v%v", prefix, "filter.limit"), 100, "Specifies the limit") - cmdFlags.BoolVar((&DefaultConfig.Filter.Asc), fmt.Sprintf("%v%v", prefix, "filter.asc"), false, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.fieldSelector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") + cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") + cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") + cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") return cmdFlags } diff --git a/cmd/config/subcommand/project/config_flags_test.go b/cmd/config/subcommand/project/config_flags_test.go index 50fcfad9d2..52668bcf14 100755 --- a/cmd/config/subcommand/project/config_flags_test.go +++ b/cmd/config/subcommand/project/config_flags_test.go @@ -99,13 +99,13 @@ func TestConfig_SetFlags(t *testing.T) { cmdFlags := actual.GetPFlagSet("") assert.True(t, cmdFlags.HasFlags()) - t.Run("Test_filter.field-selector", func(t *testing.T) { + t.Run("Test_filter.fieldSelector", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.field-selector", testValue) - if vString, err := cmdFlags.GetString("filter.field-selector"); err == nil { + cmdFlags.Set("filter.fieldSelector", testValue) + if vString, err := cmdFlags.GetString("filter.fieldSelector"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.FieldSelector) } else { @@ -113,13 +113,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.sort-by", func(t *testing.T) { + t.Run("Test_filter.sortBy", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.sort-by", testValue) - if vString, err := cmdFlags.GetString("filter.sort-by"); err == nil { + cmdFlags.Set("filter.sortBy", testValue) + if vString, err := cmdFlags.GetString("filter.sortBy"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.SortBy) } else { diff --git a/cmd/config/subcommand/project/project_config.go b/cmd/config/subcommand/project/project_config.go index e5a7850595..8692a746cd 100644 --- a/cmd/config/subcommand/project/project_config.go +++ b/cmd/config/subcommand/project/project_config.go @@ -4,7 +4,7 @@ import ( "github.com/flyteorg/flytectl/pkg/filters" ) -//go:generate pflags Config --default-var DefaultConfig +//go:generate pflags Config --default-var DefaultConfig --bind-default-var var ( DefaultConfig = &Config{ Filter: filters.DefaultFilter, diff --git a/cmd/config/subcommand/register/filesconfig_flags.go b/cmd/config/subcommand/register/filesconfig_flags.go index a28aead6e5..9ddea3a547 100755 --- a/cmd/config/subcommand/register/filesconfig_flags.go +++ b/cmd/config/subcommand/register/filesconfig_flags.go @@ -4,21 +4,58 @@ package register import ( + "encoding/json" + "reflect" + "fmt" "github.com/spf13/pflag" ) +// If v` is a pointer, it will get its element value or the zero value of the element type. +// If v is not a pointer, it will return it as is. +func (FilesConfig) elemValueOrNil(v interface{}) interface{} { + if t := reflect.TypeOf(v); t.Kind() == reflect.Ptr { + if reflect.ValueOf(v).IsNil() { + return reflect.Zero(t.Elem()).Interface() + } else { + return reflect.ValueOf(v).Interface() + } + } else if v == nil { + return reflect.Zero(t).Interface() + } + + return v +} + +func (FilesConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + +func (FilesConfig) mustMarshalJSON(v json.Marshaler) string { + raw, err := v.MarshalJSON() + if err != nil { + panic(err) + } + + return string(raw) +} + // GetPFlagSet will return strongly types pflags for all fields in FilesConfig and its nested types. The format of the // flags is json-name.json-sub-name... etc. func (cfg FilesConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("FilesConfig", pflag.ExitOnError) - cmdFlags.StringVarP(&DefaultFilesConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), "v", DefaultFilesConfig.Version, "version of the entity to be registered with flyte.") - cmdFlags.BoolVarP(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), "", DefaultFilesConfig.ContinueOnError, "continue on error when registering files.") - cmdFlags.BoolVarP(&DefaultFilesConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), "a", DefaultFilesConfig.Archive, "pass in archive file either an http link or local path.") - cmdFlags.StringVarP(&DefaultFilesConfig.AssumableIamRole, fmt.Sprintf("%v%v", prefix, "assumableIamRole"), "i", DefaultFilesConfig.AssumableIamRole, " Custom assumable iam auth role to register launch plans with.") - cmdFlags.StringVarP(&DefaultFilesConfig.K8ServiceAccount, fmt.Sprintf("%v%v", prefix, "k8ServiceAccount"), "k", DefaultFilesConfig.K8ServiceAccount, " custom kubernetes service account auth role to register launch plans with.") - cmdFlags.StringVarP(&DefaultFilesConfig.OutputLocationPrefix, fmt.Sprintf("%v%v", prefix, "outputLocationPrefix"), "l", DefaultFilesConfig.OutputLocationPrefix, " custom output location prefix for offloaded types (files/schemas).") + cmdFlags.StringVar(&DefaultFilesConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultFilesConfig.Version, "version of the entity to be registered with flyte.") + cmdFlags.BoolVar(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), DefaultFilesConfig.ContinueOnError, "continue on error when registering files.") + cmdFlags.BoolVar(&DefaultFilesConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), DefaultFilesConfig.Archive, "pass in archive file either an http link or local path.") + cmdFlags.StringVar(&DefaultFilesConfig.AssumableIamRole, fmt.Sprintf("%v%v", prefix, "assumableIamRole"), DefaultFilesConfig.AssumableIamRole, " custom assumable iam auth role to register launch plans with.") + cmdFlags.StringVar(&DefaultFilesConfig.K8ServiceAccount, fmt.Sprintf("%v%v", prefix, "k8ServiceAccount"), DefaultFilesConfig.K8ServiceAccount, " custom kubernetes service account auth role to register launch plans with.") + cmdFlags.StringVar(&DefaultFilesConfig.OutputLocationPrefix, fmt.Sprintf("%v%v", prefix, "outputLocationPrefix"), DefaultFilesConfig.OutputLocationPrefix, " custom output location prefix for offloaded types (files/schemas).") cmdFlags.StringVar(&DefaultFilesConfig.SourceUploadPath, fmt.Sprintf("%v%v", prefix, "sourceUploadPath"), DefaultFilesConfig.SourceUploadPath, " Location for source code in storage.") return cmdFlags } diff --git a/cmd/config/subcommand/sandbox/config_flags.go b/cmd/config/subcommand/sandbox/config_flags.go index ebecc0a5b9..b727f8a04d 100755 --- a/cmd/config/subcommand/sandbox/config_flags.go +++ b/cmd/config/subcommand/sandbox/config_flags.go @@ -4,11 +4,48 @@ package sandbox import ( + "encoding/json" + "reflect" + "fmt" "github.com/spf13/pflag" ) +// If v is a pointer, it will get its element value or the zero value of the element type. +// If v is not a pointer, it will return it as is. +func (Config) elemValueOrNil(v interface{}) interface{} { + if t := reflect.TypeOf(v); t.Kind() == reflect.Ptr { + if reflect.ValueOf(v).IsNil() { + return reflect.Zero(t.Elem()).Interface() + } else { + return reflect.ValueOf(v).Interface() + } + } else if v == nil { + return reflect.Zero(t).Interface() + } + + return v +} + +func (Config) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + +func (Config) mustMarshalJSON(v json.Marshaler) string { + raw, err := v.MarshalJSON() + if err != nil { + panic(err) + } + + return string(raw) +} + // GetPFlagSet will return strongly types pflags for all fields in Config and its nested types. The format of the // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { diff --git a/cmd/config/subcommand/sandbox/sandbox_config.go b/cmd/config/subcommand/sandbox/sandbox_config.go index afe85beddf..833a950495 100644 --- a/cmd/config/subcommand/sandbox/sandbox_config.go +++ b/cmd/config/subcommand/sandbox/sandbox_config.go @@ -1,6 +1,6 @@ package sandbox -//go:generate pflags Config --default-var DefaultConfig +//go:generate pflags Config --default-var DefaultConfig --bind-default-var var ( DefaultConfig = &Config{} ) diff --git a/cmd/config/subcommand/task/config_flags.go b/cmd/config/subcommand/task/config_flags.go index 4c48a38e6c..3138439017 100755 --- a/cmd/config/subcommand/task/config_flags.go +++ b/cmd/config/subcommand/task/config_flags.go @@ -50,13 +50,12 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultConfig.ExecFile), fmt.Sprintf("%v%v", prefix, "execFile"), DefaultConfig.ExecFile, "execution file name to be used for generating execution spec of a single task.") - cmdFlags.StringVar(&(DefaultConfig.Version), fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "version of the task to be fetched.") - cmdFlags.BoolVar(&(DefaultConfig.Latest), fmt.Sprintf("%v%v", prefix, "latest"), DefaultConfig.Latest, "flag to indicate to fetch the latest version, version flag will be ignored in this case") - - cmdFlags.StringVar(&(DefaultConfig.Filter.FieldSelector), fmt.Sprintf("%v%v", prefix, "filter.field-selector"), *new(string), "Specifies the Field selector") - cmdFlags.StringVar((&DefaultConfig.Filter.SortBy), fmt.Sprintf("%v%v", prefix, "filter.sort-by"), *new(string), "Specifies which field to sort result by ") - cmdFlags.Int32Var((&DefaultConfig.Filter.Limit), fmt.Sprintf("%v%v", prefix, "filter.limit"), 100, "Specifies the limit") - cmdFlags.BoolVar((&DefaultConfig.Filter.Asc), fmt.Sprintf("%v%v", prefix, "filter.asc"), false, "Specifies the sorting order. By default flytectl sort result in descending order") + cmdFlags.StringVar(&DefaultConfig.ExecFile, fmt.Sprintf("%v%v", prefix, "execFile"), DefaultConfig.ExecFile, "execution file name to be used for generating execution spec of a single task.") + cmdFlags.StringVar(&DefaultConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "version of the task to be fetched.") + cmdFlags.BoolVar(&DefaultConfig.Latest, fmt.Sprintf("%v%v", prefix, "latest"), DefaultConfig.Latest, " flag to indicate to fetch the latest version, version flag will be ignored in this case") + cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.fieldSelector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") + cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") + cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") + cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") return cmdFlags } diff --git a/cmd/config/subcommand/task/config_flags_test.go b/cmd/config/subcommand/task/config_flags_test.go index bea2ff142e..844d031a5a 100755 --- a/cmd/config/subcommand/task/config_flags_test.go +++ b/cmd/config/subcommand/task/config_flags_test.go @@ -141,13 +141,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.field-selector", func(t *testing.T) { + t.Run("Test_filter.fieldSelector", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.field-selector", testValue) - if vString, err := cmdFlags.GetString("filter.field-selector"); err == nil { + cmdFlags.Set("filter.fieldSelector", testValue) + if vString, err := cmdFlags.GetString("filter.fieldSelector"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.FieldSelector) } else { @@ -155,13 +155,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.sort-by", func(t *testing.T) { + t.Run("Test_filter.sortBy", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.sort-by", testValue) - if vString, err := cmdFlags.GetString("filter.sort-by"); err == nil { + cmdFlags.Set("filter.sortBy", testValue) + if vString, err := cmdFlags.GetString("filter.sortBy"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.SortBy) } else { diff --git a/cmd/config/subcommand/task/task_config.go b/cmd/config/subcommand/task/task_config.go index 241a1c1fab..1e0d6a2bec 100644 --- a/cmd/config/subcommand/task/task_config.go +++ b/cmd/config/subcommand/task/task_config.go @@ -2,7 +2,7 @@ package task import "github.com/flyteorg/flytectl/pkg/filters" -//go:generate pflags Config --default-var DefaultConfig +//go:generate pflags Config --default-var DefaultConfig --bind-default-var var ( DefaultConfig = &Config{ Filter: filters.DefaultFilter, diff --git a/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go b/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go index b335257d99..d1128e5e9e 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go +++ b/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go @@ -28,6 +28,15 @@ func (AttrDeleteConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrDeleteConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrDeleteConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrDeleteConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrDeleteConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultDelConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") + cmdFlags.StringVar(&DefaultDelConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultDelConfig.AttrFile, "attribute file name to be used for delete attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go b/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go index 3c219496ae..f41f531f3f 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go +++ b/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrDeleteConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(val, result)) } -func testDecodeSlice_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrDeleteConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrDeleteConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrDeleteConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultDelConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go b/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go index 761baa5c3a..0efc338768 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go +++ b/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go @@ -28,6 +28,15 @@ func (AttrFetchConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrFetchConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrFetchConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrFetchConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrFetchConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultFetchConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") + cmdFlags.StringVar(&DefaultFetchConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultFetchConfig.AttrFile, "attribute file name to be used for generating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go b/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go index 1b91152a97..038f8a893c 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go +++ b/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrFetchConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(val, result)) } -func testDecodeSlice_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrFetchConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrFetchConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrFetchConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultFetchConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go b/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go index b94b102bc6..e57de741e7 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go +++ b/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go @@ -28,6 +28,15 @@ func (AttrUpdateConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (AttrUpdateConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,6 +50,6 @@ func (AttrUpdateConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg AttrUpdateConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("AttrUpdateConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(DefaultUpdateConfig.AttrFile), fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") + cmdFlags.StringVar(&DefaultUpdateConfig.AttrFile, fmt.Sprintf("%v%v", prefix, "attrFile"), DefaultUpdateConfig.AttrFile, "attribute file name to be used for updating attribute for the resource type.") return cmdFlags } diff --git a/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go b/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go index 2672552de4..06f17f631c 100755 --- a/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go +++ b/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_AttrUpdateConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(val, result)) } -func testDecodeSlice_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_AttrUpdateConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_AttrUpdateConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestAttrUpdateConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_attrFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("attrFile"); err == nil { - assert.Equal(t, string(DefaultUpdateConfig.AttrFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/config/subcommand/taskresourceattribute/delete_config.go b/cmd/config/subcommand/taskresourceattribute/delete_config.go index 6c513cafe0..6d88a180a7 100644 --- a/cmd/config/subcommand/taskresourceattribute/delete_config.go +++ b/cmd/config/subcommand/taskresourceattribute/delete_config.go @@ -1,6 +1,6 @@ package taskresourceattribute -//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig +//go:generate pflags AttrDeleteConfig --default-var DefaultDelConfig --bind-default-var // AttrDeleteConfig Matchable resource attributes configuration passed from command line type AttrDeleteConfig struct { diff --git a/cmd/config/subcommand/taskresourceattribute/fetch_config.go b/cmd/config/subcommand/taskresourceattribute/fetch_config.go index 6909229c30..1fe6de9937 100644 --- a/cmd/config/subcommand/taskresourceattribute/fetch_config.go +++ b/cmd/config/subcommand/taskresourceattribute/fetch_config.go @@ -1,6 +1,6 @@ package taskresourceattribute -//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig +//go:generate pflags AttrFetchConfig --default-var DefaultFetchConfig --bind-default-var type AttrFetchConfig struct { AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` diff --git a/cmd/config/subcommand/taskresourceattribute/update_config.go b/cmd/config/subcommand/taskresourceattribute/update_config.go index d9ea24ab77..2dd2451e9c 100644 --- a/cmd/config/subcommand/taskresourceattribute/update_config.go +++ b/cmd/config/subcommand/taskresourceattribute/update_config.go @@ -1,6 +1,6 @@ package taskresourceattribute -//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig +//go:generate pflags AttrUpdateConfig --default-var DefaultUpdateConfig --bind-default-var // AttrUpdateConfig Matchable resource attributes configuration passed from command line type AttrUpdateConfig struct { diff --git a/cmd/config/subcommand/workflow/config_flags.go b/cmd/config/subcommand/workflow/config_flags.go index 5765379fe6..29bc7fca54 100755 --- a/cmd/config/subcommand/workflow/config_flags.go +++ b/cmd/config/subcommand/workflow/config_flags.go @@ -52,8 +52,8 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) cmdFlags.StringVar(&DefaultConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultConfig.Version, "version of the workflow to be fetched.") cmdFlags.BoolVar(&DefaultConfig.Latest, fmt.Sprintf("%v%v", prefix, "latest"), DefaultConfig.Latest, " flag to indicate to fetch the latest version, version flag will be ignored in this case") - cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.field-selector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") - cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sort-by"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") + cmdFlags.StringVar(&DefaultConfig.Filter.FieldSelector, fmt.Sprintf("%v%v", prefix, "filter.fieldSelector"), DefaultConfig.Filter.FieldSelector, "Specifies the Field selector") + cmdFlags.StringVar(&DefaultConfig.Filter.SortBy, fmt.Sprintf("%v%v", prefix, "filter.sortBy"), DefaultConfig.Filter.SortBy, "Specifies which field to sort results ") cmdFlags.Int32Var(&DefaultConfig.Filter.Limit, fmt.Sprintf("%v%v", prefix, "filter.limit"), DefaultConfig.Filter.Limit, "Specifies the limit") cmdFlags.BoolVar(&DefaultConfig.Filter.Asc, fmt.Sprintf("%v%v", prefix, "filter.asc"), DefaultConfig.Filter.Asc, "Specifies the sorting order. By default flytectl sort result in descending order") return cmdFlags diff --git a/cmd/config/subcommand/workflow/config_flags_test.go b/cmd/config/subcommand/workflow/config_flags_test.go index 86998d7788..4011d8e4f3 100755 --- a/cmd/config/subcommand/workflow/config_flags_test.go +++ b/cmd/config/subcommand/workflow/config_flags_test.go @@ -127,13 +127,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.field-selector", func(t *testing.T) { + t.Run("Test_filter.fieldSelector", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.field-selector", testValue) - if vString, err := cmdFlags.GetString("filter.field-selector"); err == nil { + cmdFlags.Set("filter.fieldSelector", testValue) + if vString, err := cmdFlags.GetString("filter.fieldSelector"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.FieldSelector) } else { @@ -141,13 +141,13 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) - t.Run("Test_filter.sort-by", func(t *testing.T) { + t.Run("Test_filter.sortBy", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("filter.sort-by", testValue) - if vString, err := cmdFlags.GetString("filter.sort-by"); err == nil { + cmdFlags.Set("filter.sortBy", testValue) + if vString, err := cmdFlags.GetString("filter.sortBy"); err == nil { testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.Filter.SortBy) } else { diff --git a/cmd/create/execution.go b/cmd/create/execution.go index f765e786b2..4fdea5214d 100644 --- a/cmd/create/execution.go +++ b/cmd/create/execution.go @@ -127,7 +127,7 @@ Usage ` ) -//go:generate pflags ExecutionConfig --default-var executionConfig +//go:generate pflags ExecutionConfig --default-var executionConfig --bind-default-var // ExecutionConfig hold configuration for create execution flags and configuration of the actual task or workflow to be launched. type ExecutionConfig struct { diff --git a/cmd/create/executionconfig_flags.go b/cmd/create/executionconfig_flags.go index 974c284b0b..5fb13bbbe8 100755 --- a/cmd/create/executionconfig_flags.go +++ b/cmd/create/executionconfig_flags.go @@ -28,6 +28,15 @@ func (ExecutionConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (ExecutionConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (ExecutionConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,11 +50,11 @@ func (ExecutionConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg ExecutionConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("ExecutionConfig", pflag.ExitOnError) - cmdFlags.StringVar(&(executionConfig.ExecFile), fmt.Sprintf("%v%v", prefix, "execFile"), executionConfig.ExecFile, "file for the execution params.If not specified defaults to <_name>.execution_spec.yaml") - cmdFlags.StringVar(&(executionConfig.TargetDomain), fmt.Sprintf("%v%v", prefix, "targetDomain"), executionConfig.TargetDomain, "project where execution needs to be created.If not specified configured domain would be used.") - cmdFlags.StringVar(&(executionConfig.TargetProject), fmt.Sprintf("%v%v", prefix, "targetProject"), executionConfig.TargetProject, "project where execution needs to be created.If not specified configured project would be used.") - cmdFlags.StringVar(&(executionConfig.KubeServiceAcct), fmt.Sprintf("%v%v", prefix, "kubeServiceAcct"), executionConfig.KubeServiceAcct, "kubernetes service account AuthRole for launching execution.") - cmdFlags.StringVar(&(executionConfig.IamRoleARN), fmt.Sprintf("%v%v", prefix, "iamRoleARN"), executionConfig.IamRoleARN, "iam role ARN AuthRole for launching execution.") - cmdFlags.StringVar(&(executionConfig.Relaunch), fmt.Sprintf("%v%v", prefix, "relaunch"), executionConfig.Relaunch, "execution id to be relaunched.") + cmdFlags.StringVar(&executionConfig.ExecFile, fmt.Sprintf("%v%v", prefix, "execFile"), executionConfig.ExecFile, "file for the execution params.If not specified defaults to <_name>.execution_spec.yaml") + cmdFlags.StringVar(&executionConfig.TargetDomain, fmt.Sprintf("%v%v", prefix, "targetDomain"), executionConfig.TargetDomain, "project where execution needs to be created.If not specified configured domain would be used.") + cmdFlags.StringVar(&executionConfig.TargetProject, fmt.Sprintf("%v%v", prefix, "targetProject"), executionConfig.TargetProject, "project where execution needs to be created.If not specified configured project would be used.") + cmdFlags.StringVar(&executionConfig.KubeServiceAcct, fmt.Sprintf("%v%v", prefix, "kubeServiceAcct"), executionConfig.KubeServiceAcct, "kubernetes service account AuthRole for launching execution.") + cmdFlags.StringVar(&executionConfig.IamRoleARN, fmt.Sprintf("%v%v", prefix, "iamRoleARN"), executionConfig.IamRoleARN, "iam role ARN AuthRole for launching execution.") + cmdFlags.StringVar(&executionConfig.Relaunch, fmt.Sprintf("%v%v", prefix, "relaunch"), executionConfig.Relaunch, "execution id to be relaunched.") return cmdFlags } diff --git a/cmd/create/executionconfig_flags_test.go b/cmd/create/executionconfig_flags_test.go index bf7ab9c47b..9e35676125 100755 --- a/cmd/create/executionconfig_flags_test.go +++ b/cmd/create/executionconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_ExecutionConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_ExecutionConfig(val, result)) } -func testDecodeSlice_ExecutionConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_ExecutionConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_ExecutionConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestExecutionConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_execFile", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("execFile"); err == nil { - assert.Equal(t, string(executionConfig.ExecFile), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -122,14 +114,6 @@ func TestExecutionConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_targetDomain", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("targetDomain"); err == nil { - assert.Equal(t, string(executionConfig.TargetDomain), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -144,14 +128,6 @@ func TestExecutionConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_targetProject", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("targetProject"); err == nil { - assert.Equal(t, string(executionConfig.TargetProject), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -166,14 +142,6 @@ func TestExecutionConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_kubeServiceAcct", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("kubeServiceAcct"); err == nil { - assert.Equal(t, string(executionConfig.KubeServiceAcct), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -188,21 +156,27 @@ func TestExecutionConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_iamRoleARN", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("iamRoleARN", testValue) if vString, err := cmdFlags.GetString("iamRoleARN"); err == nil { - assert.Equal(t, string(executionConfig.IamRoleARN), vString) + testDecodeJson_ExecutionConfig(t, fmt.Sprintf("%v", vString), &actual.IamRoleARN) + } else { assert.FailNow(t, err.Error()) } }) + }) + t.Run("Test_relaunch", func(t *testing.T) { t.Run("Override", func(t *testing.T) { testValue := "1" - cmdFlags.Set("iamRoleARN", testValue) - if vString, err := cmdFlags.GetString("iamRoleARN"); err == nil { - testDecodeJson_ExecutionConfig(t, fmt.Sprintf("%v", vString), &actual.IamRoleARN) + cmdFlags.Set("relaunch", testValue) + if vString, err := cmdFlags.GetString("relaunch"); err == nil { + testDecodeJson_ExecutionConfig(t, fmt.Sprintf("%v", vString), &actual.Relaunch) } else { assert.FailNow(t, err.Error()) diff --git a/cmd/get/execution.go b/cmd/get/execution.go index f547789349..2e8232ca7e 100644 --- a/cmd/get/execution.go +++ b/cmd/get/execution.go @@ -30,13 +30,13 @@ Retrieves execution by name within project and domain. Retrieves all the executions with filters. :: - bin/flytectl get execution -p flytesnacks -d development --filter.field-selector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" + bin/flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" Retrieves all the execution with limit and sorting. :: - bin/flytectl get execution -p flytesnacks -d development --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get execution -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the execution within project and domain in yaml format diff --git a/cmd/get/launch_plan.go b/cmd/get/launch_plan.go index 9edff6ab92..ec90a62fd2 100644 --- a/cmd/get/launch_plan.go +++ b/cmd/get/launch_plan.go @@ -43,18 +43,18 @@ Retrieves particular version of launchplan by name within project and domain. Retrieves all the launch plans with filters. :: - bin/flytectl get launchplan -p flytesnacks -d development --filter.field-selector="name=core.basic.lp.go_greet" + bin/flytectl get launchplan -p flytesnacks -d development --filter.fieldSelector="name=core.basic.lp.go_greet" Retrieves launch plans entity search across all versions with filters. :: - bin/flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.field-selector="version=v1" + bin/flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="version=v1" Retrieves all the launch plans with limit and sorting. :: - bin/flytectl get launchplan -p flytesnacks -d development --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get launchplan -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the launchplan within project and domain in yaml format. diff --git a/cmd/get/project.go b/cmd/get/project.go index 4d13950e1e..10148a1c07 100644 --- a/cmd/get/project.go +++ b/cmd/get/project.go @@ -31,12 +31,12 @@ Retrieves project by name Retrieves all the projects with filters. :: - bin/flytectl get project --filter.field-selector="project.name=flytesnacks" + bin/flytectl get project --filter.fieldSelector="project.name=flytesnacks" Retrieves all the projects with limit and sorting. :: - bin/flytectl get project --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get project --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the projects in yaml format diff --git a/cmd/get/task.go b/cmd/get/task.go index e25206a55f..49c586f433 100644 --- a/cmd/get/task.go +++ b/cmd/get/task.go @@ -43,17 +43,17 @@ Retrieves particular version of task by name within project and domain. Retrieves all the tasks with filters. :: - bin/flytectl get task -p flytesnacks -d development --filter.field-selector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" + bin/flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" Retrieve a specific task with filters. :: - bin/flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.field-selector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" + bin/flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" Retrieves all the task with limit and sorting. :: - bin/flytectl get -p flytesnacks -d development task --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get -p flytesnacks -d development task --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the tasks within project and domain in yaml format. :: diff --git a/cmd/get/workflow.go b/cmd/get/workflow.go index 4174f96c1a..8fba30d2cd 100644 --- a/cmd/get/workflow.go +++ b/cmd/get/workflow.go @@ -44,17 +44,17 @@ Retrieves particular version of workflow by name within project and domain. Retrieves all the workflows with filters. :: - bin/flytectl get workflow -p flytesnacks -d development --filter.field-selector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema" + bin/flytectl get workflow -p flytesnacks -d development --filter.fieldSelector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema" Retrieve specific workflow with filters. :: - bin/flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.field-selector="workflow.version=v1" + bin/flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="workflow.version=v1" Retrieves all the workflows with limit and sorting. :: - bin/flytectl get -p flytesnacks -d development workflow --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get -p flytesnacks -d development workflow --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the workflow within project and domain in yaml format. diff --git a/cmd/register/files.go b/cmd/register/files.go index d758adce98..210bb1bba2 100644 --- a/cmd/register/files.go +++ b/cmd/register/files.go @@ -26,12 +26,12 @@ There is no difference between registration and fast registration, In fast regis SourceUploadPath is an optional flag. By default, flytectl will create SourceUploadPath from your storage config. In case of s3 flytectl will upload code base in s3://{{DEFINE_BUCKET_IN_STORAGE_CONFIG}}/fast/{{VERSION}}-fast{{MD5_CREATED_BY_PYFLYTE}.tar.gz}. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 In case of fast registration, If the SourceUploadPath flag is defined then In this case flytectl will not use the default directory for uploading the source code, it will override the destination path on the registration :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 --SourceUploadPath="s3://dummy/fast" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 --SourceUploadPath="s3://dummy/fast" Using archive file.Currently supported are .tgz and .tar extension files and can be local or remote file served through http/https. Use --archive flag. @@ -60,7 +60,7 @@ Using short format of continueOnError flag Overriding the default version v1 using version string. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 Change the o/p format has not effect on registration. The O/p is currently available only in table format. @@ -72,19 +72,19 @@ Override IamRole during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -i "arn:aws:iam::123456789:role/dummy" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -i "arn:aws:iam::123456789:role/dummy" Override Kubernetes service account during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -k "kubernetes-service-account" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -k "kubernetes-service-account" Override Output location prefix during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -l "s3://dummy/prefix" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -l "s3://dummy/prefix" Usage ` diff --git a/cmd/update/named_entity.go b/cmd/update/named_entity.go index 5c3391d708..da5380554e 100644 --- a/cmd/update/named_entity.go +++ b/cmd/update/named_entity.go @@ -10,7 +10,7 @@ import ( "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" ) -//go:generate pflags NamedEntityConfig --default-var namedEntityConfig +//go:generate pflags NamedEntityConfig --default-var namedEntityConfig --bind-default-var var ( namedEntityConfig = &NamedEntityConfig{} diff --git a/cmd/update/namedentityconfig_flags.go b/cmd/update/namedentityconfig_flags.go index 3d61711bec..e1bd681341 100755 --- a/cmd/update/namedentityconfig_flags.go +++ b/cmd/update/namedentityconfig_flags.go @@ -28,6 +28,15 @@ func (NamedEntityConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (NamedEntityConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (NamedEntityConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -39,10 +48,10 @@ func (NamedEntityConfig) mustMarshalJSON(v json.Marshaler) string { // GetPFlagSet will return strongly types pflags for all fields in NamedEntityConfig and its nested types. The format of the // flags is json-name.json-sub-name... etc. -func (n NamedEntityConfig) GetPFlagSet(prefix string) *pflag.FlagSet { +func (cfg NamedEntityConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("NamedEntityConfig", pflag.ExitOnError) - cmdFlags.BoolVar(&(namedEntityConfig.Activate), fmt.Sprintf("%v%v", prefix, "activate"), *new(bool), "Activates the named entity specified as argument.") - cmdFlags.BoolVar(&(namedEntityConfig.Archive), fmt.Sprintf("%v%v", prefix, "archive"), *new(bool), "Archives the named entity specified as argument.") - cmdFlags.StringVar(&(namedEntityConfig.Description), fmt.Sprintf("%v%v", prefix, "description"), namedEntityConfig.Description, "description of the namedentity.") + cmdFlags.BoolVar(&namedEntityConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), namedEntityConfig.Archive, "archive named entity.") + cmdFlags.BoolVar(&namedEntityConfig.Activate, fmt.Sprintf("%v%v", prefix, "activate"), namedEntityConfig.Activate, "activate the named entity.") + cmdFlags.StringVar(&namedEntityConfig.Description, fmt.Sprintf("%v%v", prefix, "description"), namedEntityConfig.Description, "description of the named entity.") return cmdFlags } diff --git a/cmd/update/namedentityconfig_flags_test.go b/cmd/update/namedentityconfig_flags_test.go index 1f9506481b..528f913d63 100755 --- a/cmd/update/namedentityconfig_flags_test.go +++ b/cmd/update/namedentityconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_NamedEntityConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_NamedEntityConfig(val, result)) } -func testDecodeSlice_NamedEntityConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_NamedEntityConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_NamedEntityConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestNamedEntityConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_archive", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vBool, err := cmdFlags.GetBool("archive"); err == nil { - assert.Equal(t, bool(namedEntityConfig.Archive), vBool) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -122,14 +114,6 @@ func TestNamedEntityConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_activate", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vBool, err := cmdFlags.GetBool("activate"); err == nil { - assert.Equal(t, bool(namedEntityConfig.Activate), vBool) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -144,14 +128,6 @@ func TestNamedEntityConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_description", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vString, err := cmdFlags.GetString("description"); err == nil { - assert.Equal(t, string(namedEntityConfig.Description), vString) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/update/project.go b/cmd/update/project.go index 0a1f5415d7..86d7bb616a 100644 --- a/cmd/update/project.go +++ b/cmd/update/project.go @@ -11,7 +11,7 @@ import ( "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" ) -//go:generate pflags ProjectConfig +//go:generate pflags ProjectConfig --default-var DefaultProjectConfig --bind-default-var // Config hold configuration for project update flags. type ProjectConfig struct { @@ -34,40 +34,29 @@ Archives project named flytesnacks. bin/flytectl update project -p flytesnacks --archiveProject -Activates project named flytesnacks using short option -t. -:: - - bin/flytectl update project -p flytesnacks -t - -Archives project named flytesnacks using short option -a. - -:: - - bin/flytectl update project flytesnacks -a - Incorrect usage when passing both archive and activate. :: - bin/flytectl update project flytesnacks -a -t + bin/flytectl update project flytesnacks --archiveProject --activateProject Incorrect usage when passing unknown-project. :: - bin/flytectl update project unknown-project -a + bin/flytectl update project unknown-project --archiveProject Incorrect usage when passing valid project using -p option. :: - bin/flytectl update project unknown-project -a -p known-project + bin/flytectl update project unknown-project --archiveProject -p known-project Usage ` ) -var projectConfig = &ProjectConfig{} +var DefaultProjectConfig = &ProjectConfig{} func updateProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { id := config.GetConfig().Project @@ -75,8 +64,8 @@ func updateProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.Comma fmt.Printf(clierrors.ErrProjectNotPassed) return nil } - archiveProject := projectConfig.ArchiveProject - activateProject := projectConfig.ActivateProject + archiveProject := DefaultProjectConfig.ArchiveProject + activateProject := DefaultProjectConfig.ActivateProject if activateProject == archiveProject { return fmt.Errorf(clierrors.ErrInvalidStateUpdate) } diff --git a/cmd/update/project_test.go b/cmd/update/project_test.go index e3eac5ff84..9db9f8cf46 100644 --- a/cmd/update/project_test.go +++ b/cmd/update/project_test.go @@ -37,7 +37,7 @@ func modifyProjectFlags(archiveProject *bool, newArchiveVal bool, activateProjec func TestActivateProjectFunc(t *testing.T) { setup() updateProjectSetup() - modifyProjectFlags(&(projectConfig.ArchiveProject), false, &(projectConfig.ActivateProject), true) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), false, &(DefaultProjectConfig.ActivateProject), true) mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, nil) err = updateProjectsFunc(ctx, args, cmdCtx) assert.Nil(t, err) @@ -48,7 +48,7 @@ func TestActivateProjectFunc(t *testing.T) { func TestActivateProjectFuncWithError(t *testing.T) { setup() updateProjectSetup() - modifyProjectFlags(&(projectConfig.ArchiveProject), false, &(projectConfig.ActivateProject), true) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), false, &(DefaultProjectConfig.ActivateProject), true) mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, errors.New("Error Updating Project")) err = updateProjectsFunc(ctx, args, cmdCtx) assert.NotNil(t, err) @@ -59,7 +59,7 @@ func TestActivateProjectFuncWithError(t *testing.T) { func TestArchiveProjectFunc(t *testing.T) { setup() updateProjectSetup() - modifyProjectFlags(&(projectConfig.ArchiveProject), true, &(projectConfig.ActivateProject), false) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), true, &(DefaultProjectConfig.ActivateProject), false) projectUpdateRequest = &admin.Project{ Id: projectValue, State: admin.Project_ARCHIVED, @@ -74,7 +74,7 @@ func TestArchiveProjectFunc(t *testing.T) { func TestArchiveProjectFuncWithError(t *testing.T) { setup() updateProjectSetup() - modifyProjectFlags(&(projectConfig.ArchiveProject), true, &(projectConfig.ActivateProject), false) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), true, &(DefaultProjectConfig.ActivateProject), false) projectUpdateRequest = &admin.Project{ Id: projectValue, State: admin.Project_ARCHIVED, @@ -90,7 +90,7 @@ func TestEmptyProjectInput(t *testing.T) { setup() updateProjectSetup() config.GetConfig().Project = "" - modifyProjectFlags(&(projectConfig.ArchiveProject), false, &(projectConfig.ActivateProject), true) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), false, &(DefaultProjectConfig.ActivateProject), true) mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, nil) err = updateProjectsFunc(ctx, args, cmdCtx) assert.Nil(t, err) @@ -101,7 +101,7 @@ func TestEmptyProjectInput(t *testing.T) { func TestInvalidInput(t *testing.T) { setup() updateProjectSetup() - modifyProjectFlags(&(projectConfig.ArchiveProject), false, &(projectConfig.ActivateProject), false) + modifyProjectFlags(&(DefaultProjectConfig.ArchiveProject), false, &(DefaultProjectConfig.ActivateProject), false) mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, nil) err = updateProjectsFunc(ctx, args, cmdCtx) assert.NotNil(t, err) diff --git a/cmd/update/projectconfig_flags.go b/cmd/update/projectconfig_flags.go index f56579fe9f..2139fb0563 100755 --- a/cmd/update/projectconfig_flags.go +++ b/cmd/update/projectconfig_flags.go @@ -28,6 +28,15 @@ func (ProjectConfig) elemValueOrNil(v interface{}) interface{} { return v } +func (ProjectConfig) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (ProjectConfig) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,7 +50,7 @@ func (ProjectConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg ProjectConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("ProjectConfig", pflag.ExitOnError) - cmdFlags.BoolVarP(&(projectConfig.ActivateProject), fmt.Sprintf("%v%v", prefix, "activateProject"), "t", *new(bool), "Activates the project specified as argument.") - cmdFlags.BoolVarP(&(projectConfig.ArchiveProject), fmt.Sprintf("%v%v", prefix, "archiveProject"), "a", *new(bool), "Archives the project specified as argument.") + cmdFlags.BoolVar(&DefaultProjectConfig.ActivateProject, fmt.Sprintf("%v%v", prefix, "activateProject"), DefaultProjectConfig.ActivateProject, "Activates the project specified as argument.") + cmdFlags.BoolVar(&DefaultProjectConfig.ArchiveProject, fmt.Sprintf("%v%v", prefix, "archiveProject"), DefaultProjectConfig.ArchiveProject, "Archives the project specified as argument.") return cmdFlags } diff --git a/cmd/update/projectconfig_flags_test.go b/cmd/update/projectconfig_flags_test.go index 4a13ad3aff..c6bc6b262c 100755 --- a/cmd/update/projectconfig_flags_test.go +++ b/cmd/update/projectconfig_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_ProjectConfig(t *testing.T, val, result interface{}) { assert.NoError(t, decode_ProjectConfig(val, result)) } -func testDecodeSlice_ProjectConfig(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_ProjectConfig(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_ProjectConfig(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestProjectConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_activateProject", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vBool, err := cmdFlags.GetBool("activateProject"); err == nil { - assert.Equal(t, bool(*new(bool)), vBool) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -122,14 +114,6 @@ func TestProjectConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_archiveProject", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vBool, err := cmdFlags.GetBool("archiveProject"); err == nil { - assert.Equal(t, bool(*new(bool)), vBool) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/cmd/update/update.go b/cmd/update/update.go index 34ab70c21c..8485f32043 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -35,7 +35,7 @@ func CreateUpdateCommand() *cobra.Command { updateResourcesFuncs := map[string]cmdCore.CommandEntry{ "launchplan": {CmdFunc: updateLPFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, Short: updateLPShort, Long: updateLPLong}, - "project": {CmdFunc: updateProjectsFunc, Aliases: []string{}, ProjectDomainNotRequired: true, PFlagProvider: projectConfig, + "project": {CmdFunc: updateProjectsFunc, Aliases: []string{}, ProjectDomainNotRequired: true, PFlagProvider: DefaultProjectConfig, Short: projectShort, Long: projectLong}, "task": {CmdFunc: updateTaskFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, Short: updateTaskShort, Long: updateTaskLong}, diff --git a/docs/source/gen/flytectl_get_execution.rst b/docs/source/gen/flytectl_get_execution.rst index 174ba88661..e81e77ac7c 100644 --- a/docs/source/gen/flytectl_get_execution.rst +++ b/docs/source/gen/flytectl_get_execution.rst @@ -24,13 +24,13 @@ Retrieves execution by name within project and domain. Retrieves all the executions with filters. :: - bin/flytectl get execution -p flytesnacks -d development --filter.field-selector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" + bin/flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200" Retrieves all the execution with limit and sorting. :: - bin/flytectl get execution -p flytesnacks -d development --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get execution -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the execution within project and domain in yaml format @@ -82,13 +82,13 @@ Options :: - --details gets node execution details. Only applicable for single execution name i.e get execution name --details - --filter.asc Specifies the sorting order. By default flytectl sort result in descending order - --filter.field-selector string Specifies the Field selector - --filter.limit int32 Specifies the limit (default 100) - --filter.sort-by string Specifies which field to sort results (default "created_at") - -h, --help help for execution - --nodeId string get task executions for given node name. + --details gets node execution details. Only applicable for single execution name i.e get execution name --details + --filter.asc Specifies the sorting order. By default flytectl sort result in descending order + --filter.fieldSelector string Specifies the Field selector + --filter.limit int32 Specifies the limit (default 100) + --filter.sortBy string Specifies which field to sort results (default "created_at") + -h, --help help for execution + --nodeId string get task executions for given node name. Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_get_launchplan.rst b/docs/source/gen/flytectl_get_launchplan.rst index f50798c59c..51c936f264 100644 --- a/docs/source/gen/flytectl_get_launchplan.rst +++ b/docs/source/gen/flytectl_get_launchplan.rst @@ -37,18 +37,18 @@ Retrieves particular version of launchplan by name within project and domain. Retrieves all the launch plans with filters. :: - bin/flytectl get launchplan -p flytesnacks -d development --filter.field-selector="name=core.basic.lp.go_greet" + bin/flytectl get launchplan -p flytesnacks -d development --filter.fieldSelector="name=core.basic.lp.go_greet" Retrieves launch plans entity search across all versions with filters. :: - bin/flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.field-selector="version=v1" + bin/flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="version=v1" Retrieves all the launch plans with limit and sorting. :: - bin/flytectl get launchplan -p flytesnacks -d development --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get launchplan -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the launchplan within project and domain in yaml format. @@ -99,14 +99,14 @@ Options :: - --execFile string execution file name to be used for generating execution spec of a single launchplan. - --filter.asc Specifies the sorting order. By default flytectl sort result in descending order - --filter.field-selector string Specifies the Field selector - --filter.limit int32 Specifies the limit (default 100) - --filter.sort-by string Specifies which field to sort result by - -h, --help help for launchplan - --latest flag to indicate to fetch the latest version, version flag will be ignored in this case - --version string version of the launchplan to be fetched. + --execFile string execution file name to be used for generating execution spec of a single launchplan. + --filter.asc Specifies the sorting order. By default flytectl sort result in descending order + --filter.fieldSelector string Specifies the Field selector + --filter.limit int32 Specifies the limit (default 100) + --filter.sortBy string Specifies which field to sort results (default "created_at") + -h, --help help for launchplan + --latest flag to indicate to fetch the latest version, version flag will be ignored in this case + --version string version of the launchplan to be fetched. Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_get_project.rst b/docs/source/gen/flytectl_get_project.rst index 7aafa4e606..541f9e9a2d 100644 --- a/docs/source/gen/flytectl_get_project.rst +++ b/docs/source/gen/flytectl_get_project.rst @@ -24,12 +24,12 @@ Retrieves project by name Retrieves all the projects with filters. :: - bin/flytectl get project --filter.field-selector="project.name=flytesnacks" + bin/flytectl get project --filter.fieldSelector="project.name=flytesnacks" Retrieves all the projects with limit and sorting. :: - bin/flytectl get project --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get project --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the projects in yaml format @@ -55,11 +55,11 @@ Options :: - --filter.asc Specifies the sorting order. By default flytectl sort result in descending order - --filter.field-selector string Specifies the Field selector - --filter.limit int32 Specifies the limit (default 100) - --filter.sort-by string Specifies which field to sort result by - -h, --help help for project + --filter.asc Specifies the sorting order. By default flytectl sort result in descending order + --filter.fieldSelector string Specifies the Field selector + --filter.limit int32 Specifies the limit (default 100) + --filter.sortBy string Specifies which field to sort results (default "created_at") + -h, --help help for project Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_get_task.rst b/docs/source/gen/flytectl_get_task.rst index c94f945b18..49148043bb 100644 --- a/docs/source/gen/flytectl_get_task.rst +++ b/docs/source/gen/flytectl_get_task.rst @@ -36,17 +36,17 @@ Retrieves particular version of task by name within project and domain. Retrieves all the tasks with filters. :: - bin/flytectl get task -p flytesnacks -d development --filter.field-selector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" + bin/flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1" Retrieve a specific task with filters. :: - bin/flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.field-selector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" + bin/flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z" Retrieves all the task with limit and sorting. :: - bin/flytectl get -p flytesnacks -d development task --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get -p flytesnacks -d development task --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the tasks within project and domain in yaml format. :: @@ -95,14 +95,14 @@ Options :: - --execFile string execution file name to be used for generating execution spec of a single task. - --filter.asc Specifies the sorting order. By default flytectl sort result in descending order - --filter.field-selector string Specifies the Field selector - --filter.limit int32 Specifies the limit (default 100) - --filter.sort-by string Specifies which field to sort result by - -h, --help help for task - --latest flag to indicate to fetch the latest version, version flag will be ignored in this case - --version string version of the task to be fetched. + --execFile string execution file name to be used for generating execution spec of a single task. + --filter.asc Specifies the sorting order. By default flytectl sort result in descending order + --filter.fieldSelector string Specifies the Field selector + --filter.limit int32 Specifies the limit (default 100) + --filter.sortBy string Specifies which field to sort results (default "created_at") + -h, --help help for task + --latest flag to indicate to fetch the latest version, version flag will be ignored in this case + --version string version of the task to be fetched. Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_get_workflow.rst b/docs/source/gen/flytectl_get_workflow.rst index 63a55c3a4e..6c8ec19195 100644 --- a/docs/source/gen/flytectl_get_workflow.rst +++ b/docs/source/gen/flytectl_get_workflow.rst @@ -36,17 +36,17 @@ Retrieves particular version of workflow by name within project and domain. Retrieves all the workflows with filters. :: - bin/flytectl get workflow -p flytesnacks -d development --filter.field-selector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema" + bin/flytectl get workflow -p flytesnacks -d development --filter.fieldSelector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema" Retrieve specific workflow with filters. :: - bin/flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.field-selector="workflow.version=v1" + bin/flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="workflow.version=v1" Retrieves all the workflows with limit and sorting. :: - bin/flytectl get -p flytesnacks -d development workflow --filter.sort-by=created_at --filter.limit=1 --filter.asc + bin/flytectl get -p flytesnacks -d development workflow --filter.sortBy=created_at --filter.limit=1 --filter.asc Retrieves all the workflow within project and domain in yaml format. @@ -84,13 +84,13 @@ Options :: - --filter.asc Specifies the sorting order. By default flytectl sort result in descending order - --filter.field-selector string Specifies the Field selector - --filter.limit int32 Specifies the limit (default 100) - --filter.sort-by string Specifies which field to sort results (default "created_at") - -h, --help help for workflow - --latest flag to indicate to fetch the latest version, version flag will be ignored in this case - --version string version of the workflow to be fetched. + --filter.asc Specifies the sorting order. By default flytectl sort result in descending order + --filter.fieldSelector string Specifies the Field selector + --filter.limit int32 Specifies the limit (default 100) + --filter.sortBy string Specifies which field to sort results (default "created_at") + -h, --help help for workflow + --latest flag to indicate to fetch the latest version, version flag will be ignored in this case + --version string version of the workflow to be fetched. Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_register_examples.rst b/docs/source/gen/flytectl_register_examples.rst index 1a32690879..b1929fc1ea 100644 --- a/docs/source/gen/flytectl_register_examples.rst +++ b/docs/source/gen/flytectl_register_examples.rst @@ -28,14 +28,14 @@ Options :: - -a, --archive pass in archive file either an http link or local path. - -i, --assumableIamRole string Custom assumable iam auth role to register launch plans with. + --archive pass in archive file either an http link or local path. + --assumableIamRole string custom assumable iam auth role to register launch plans with. --continueOnError continue on error when registering files. -h, --help help for examples - -k, --k8ServiceAccount string custom kubernetes service account auth role to register launch plans with. - -l, --outputLocationPrefix string custom output location prefix for offloaded types (files/schemas). + --k8ServiceAccount string custom kubernetes service account auth role to register launch plans with. + --outputLocationPrefix string custom output location prefix for offloaded types (files/schemas). --sourceUploadPath string Location for source code in storage. - -v, --version string version of the entity to be registered with flyte. (default "v1") + --version string version of the entity to be registered with flyte. (default "v1") Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_register_files.rst b/docs/source/gen/flytectl_register_files.rst index 2e3207d832..55e8bab2bb 100644 --- a/docs/source/gen/flytectl_register_files.rst +++ b/docs/source/gen/flytectl_register_files.rst @@ -20,12 +20,12 @@ There is no difference between registration and fast registration, In fast regis SourceUploadPath is an optional flag. By default, flytectl will create SourceUploadPath from your storage config. In case of s3 flytectl will upload code base in s3://{{DEFINE_BUCKET_IN_STORAGE_CONFIG}}/fast/{{VERSION}}-fast{{MD5_CREATED_BY_PYFLYTE}.tar.gz}. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 In case of fast registration, If the SourceUploadPath flag is defined then In this case flytectl will not use the default directory for uploading the source code, it will override the destination path on the registration :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 --SourceUploadPath="s3://dummy/fast" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 --SourceUploadPath="s3://dummy/fast" Using archive file.Currently supported are .tgz and .tar extension files and can be local or remote file served through http/https. Use --archive flag. @@ -54,7 +54,7 @@ Using short format of continueOnError flag Overriding the default version v1 using version string. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks -v v2 + bin/flytectl register file _pb_output/* -d development -p flytesnacks --version v2 Change the o/p format has not effect on registration. The O/p is currently available only in table format. @@ -66,19 +66,19 @@ Override IamRole during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -i "arn:aws:iam::123456789:role/dummy" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -i "arn:aws:iam::123456789:role/dummy" Override Kubernetes service account during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -k "kubernetes-service-account" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -k "kubernetes-service-account" Override Output location prefix during registration. :: - bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError -v v2 -l "s3://dummy/prefix" + bin/flytectl register file _pb_output/* -d development -p flytesnacks --continueOnError --version v2 -l "s3://dummy/prefix" Usage @@ -92,14 +92,14 @@ Options :: - -a, --archive pass in archive file either an http link or local path. - -i, --assumableIamRole string Custom assumable iam auth role to register launch plans with. + --archive pass in archive file either an http link or local path. + --assumableIamRole string custom assumable iam auth role to register launch plans with. --continueOnError continue on error when registering files. -h, --help help for files - -k, --k8ServiceAccount string custom kubernetes service account auth role to register launch plans with. - -l, --outputLocationPrefix string custom output location prefix for offloaded types (files/schemas). + --k8ServiceAccount string custom kubernetes service account auth role to register launch plans with. + --outputLocationPrefix string custom output location prefix for offloaded types (files/schemas). --sourceUploadPath string Location for source code in storage. - -v, --version string version of the entity to be registered with flyte. (default "v1") + --version string version of the entity to be registered with flyte. (default "v1") Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/gen/flytectl_update_launchplan.rst b/docs/source/gen/flytectl_update_launchplan.rst index 9c98daa2ef..0bc98036df 100644 --- a/docs/source/gen/flytectl_update_launchplan.rst +++ b/docs/source/gen/flytectl_update_launchplan.rst @@ -37,9 +37,9 @@ Options :: - --activate Activates the named entity specified as argument. - --archive Archives the named entity specified as argument. - --description string description of the namedentity. + --activate activate the named entity. + --archive archive named entity. + --description string description of the named entity. -h, --help help for launchplan Options inherited from parent commands diff --git a/docs/source/gen/flytectl_update_project.rst b/docs/source/gen/flytectl_update_project.rst index e7b4665448..437df1e0cd 100644 --- a/docs/source/gen/flytectl_update_project.rst +++ b/docs/source/gen/flytectl_update_project.rst @@ -22,34 +22,23 @@ Archives project named flytesnacks. bin/flytectl update project -p flytesnacks --archiveProject -Activates project named flytesnacks using short option -t. -:: - - bin/flytectl update project -p flytesnacks -t - -Archives project named flytesnacks using short option -a. - -:: - - bin/flytectl update project flytesnacks -a - Incorrect usage when passing both archive and activate. :: - bin/flytectl update project flytesnacks -a -t + bin/flytectl update project flytesnacks --archiveProject --activateProject Incorrect usage when passing unknown-project. :: - bin/flytectl update project unknown-project -a + bin/flytectl update project unknown-project --archiveProject Incorrect usage when passing valid project using -p option. :: - bin/flytectl update project unknown-project -a -p known-project + bin/flytectl update project unknown-project --archiveProject -p known-project Usage @@ -63,8 +52,8 @@ Options :: - -t, --activateProject Activates the project specified as argument. - -a, --archiveProject Archives the project specified as argument. + --activateProject Activates the project specified as argument. + --archiveProject Archives the project specified as argument. -h, --help help for project Options inherited from parent commands diff --git a/docs/source/gen/flytectl_update_task.rst b/docs/source/gen/flytectl_update_task.rst index 954071ee2a..f82ef9a7a1 100644 --- a/docs/source/gen/flytectl_update_task.rst +++ b/docs/source/gen/flytectl_update_task.rst @@ -37,9 +37,9 @@ Options :: - --activate Activates the named entity specified as argument. - --archive Archives the named entity specified as argument. - --description string description of the namedentity. + --activate activate the named entity. + --archive archive named entity. + --description string description of the named entity. -h, --help help for task Options inherited from parent commands diff --git a/docs/source/gen/flytectl_update_workflow.rst b/docs/source/gen/flytectl_update_workflow.rst index 14f28a4082..b9d9abc384 100644 --- a/docs/source/gen/flytectl_update_workflow.rst +++ b/docs/source/gen/flytectl_update_workflow.rst @@ -37,9 +37,9 @@ Options :: - --activate Activates the named entity specified as argument. - --archive Archives the named entity specified as argument. - --description string description of the namedentity. + --activate activate the named entity. + --archive archive named entity. + --description string description of the named entity. -h, --help help for workflow Options inherited from parent commands diff --git a/pkg/adminutils/config.go b/pkg/adminutils/config.go index f47ae8276b..71f0a3f476 100644 --- a/pkg/adminutils/config.go +++ b/pkg/adminutils/config.go @@ -2,14 +2,14 @@ package adminutils import "github.com/flyteorg/flytestdlib/config" -//go:generate pflags Config +//go:generate pflags Config --default-var DefaultConfig --bind-default-var var ( - defaultConfig = &Config{ + DefaultConfig = &Config{ MaxRecords: 500, BatchSize: 100, } - section = config.MustRegisterSection("adminutils", defaultConfig) + section = config.MustRegisterSection("adminutils", DefaultConfig) ) type Config struct { diff --git a/pkg/adminutils/config_flags.go b/pkg/adminutils/config_flags.go index 5a3c9a2c4d..f62caa371c 100755 --- a/pkg/adminutils/config_flags.go +++ b/pkg/adminutils/config_flags.go @@ -28,6 +28,15 @@ func (Config) elemValueOrNil(v interface{}) interface{} { return v } +func (Config) mustJsonMarshal(v interface{}) string { + raw, err := json.Marshal(v) + if err != nil { + panic(err) + } + + return string(raw) +} + func (Config) mustMarshalJSON(v json.Marshaler) string { raw, err := v.MarshalJSON() if err != nil { @@ -41,7 +50,7 @@ func (Config) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("Config", pflag.ExitOnError) - cmdFlags.Int(fmt.Sprintf("%v%v", prefix, "maxRecords"), defaultConfig.MaxRecords, "Maximum number of records to retrieve.") - cmdFlags.Int(fmt.Sprintf("%v%v", prefix, "batchSize"), defaultConfig.BatchSize, "Maximum number of records to retrieve per call.") + cmdFlags.IntVar(&DefaultConfig.MaxRecords, fmt.Sprintf("%v%v", prefix, "maxRecords"), DefaultConfig.MaxRecords, "Maximum number of records to retrieve.") + cmdFlags.IntVar(&DefaultConfig.BatchSize, fmt.Sprintf("%v%v", prefix, "batchSize"), DefaultConfig.BatchSize, "Maximum number of records to retrieve per call.") return cmdFlags } diff --git a/pkg/adminutils/config_flags_test.go b/pkg/adminutils/config_flags_test.go index 1f7cf5ec73..de285339d1 100755 --- a/pkg/adminutils/config_flags_test.go +++ b/pkg/adminutils/config_flags_test.go @@ -84,7 +84,7 @@ func testDecodeJson_Config(t *testing.T, val, result interface{}) { assert.NoError(t, decode_Config(val, result)) } -func testDecodeSlice_Config(t *testing.T, vStringSlice, result interface{}) { +func testDecodeRaw_Config(t *testing.T, vStringSlice, result interface{}) { assert.NoError(t, decode_Config(vStringSlice, result)) } @@ -100,14 +100,6 @@ func TestConfig_SetFlags(t *testing.T) { assert.True(t, cmdFlags.HasFlags()) t.Run("Test_maxRecords", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vInt, err := cmdFlags.GetInt("maxRecords"); err == nil { - assert.Equal(t, int(defaultConfig.MaxRecords), vInt) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" @@ -122,14 +114,6 @@ func TestConfig_SetFlags(t *testing.T) { }) }) t.Run("Test_batchSize", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - // Test that default value is set properly - if vInt, err := cmdFlags.GetInt("batchSize"); err == nil { - assert.Equal(t, int(defaultConfig.BatchSize), vInt) - } else { - assert.FailNow(t, err.Error()) - } - }) t.Run("Override", func(t *testing.T) { testValue := "1" diff --git a/pkg/adminutils/config_test.go b/pkg/adminutils/config_test.go deleted file mode 100644 index 5a8fd5134d..0000000000 --- a/pkg/adminutils/config_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package adminutils - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestGetConfig(t *testing.T) { - defaultConfig = &Config{ - MaxRecords: 500, - BatchSize: 100, - } - c := GetConfig() - assert.Equal(t, defaultConfig.BatchSize, c.BatchSize) - assert.Equal(t, defaultConfig.MaxRecords, c.MaxRecords) -} diff --git a/pkg/filters/type.go b/pkg/filters/type.go index 5dbad76923..6dabc0904d 100644 --- a/pkg/filters/type.go +++ b/pkg/filters/type.go @@ -10,8 +10,8 @@ var ( ) type Filters struct { - FieldSelector string `json:"field-selector" pflag:",Specifies the Field selector"` - SortBy string `json:"sort-by" pflag:",Specifies which field to sort results "` + FieldSelector string `json:"fieldSelector" pflag:",Specifies the Field selector"` + SortBy string `json:"sortBy" pflag:",Specifies which field to sort results "` // TODO: Support paginated queries Limit int32 `json:"limit" pflag:",Specifies the limit"` Asc bool `json:"asc" pflag:",Specifies the sorting order. By default flytectl sort result in descending order"`