From 5604bd404d393585d74df1eda79e5975d6862d88 Mon Sep 17 00:00:00 2001 From: Sean Lin Date: Thu, 8 Jul 2021 19:51:29 -0700 Subject: [PATCH] Bind pflags to default variable fields && Remove short flags as they're not supported by pflags (#124) * * Bind pflags to default variable fields * Remove short flags as they're not supported by pflags Signed-off-by: Sean Lin * Add --default-var to config.go Signed-off-by: Sean Lin * * merge change from master branch * remove config_test as the generated test conflicts with it Signed-off-by: Sean Lin * Add config_test.go to commit Signed-off-by: Sean Lin * Update command help doc Signed-off-by: Sean Lin * Use camelCase for flags Signed-off-by: Sean Lin * Remove short flags from docs Signed-off-by: Sean Lin * Update docs Signed-off-by: Sean Lin --- flytectl/cmd/config/config.go | 2 +- flytectl/cmd/config/config_flags.go | 6 +-- .../attrdeleteconfig_flags.go | 11 +++- .../attrdeleteconfig_flags_test.go | 10 +--- .../attrfetchconfig_flags.go | 11 +++- .../attrfetchconfig_flags_test.go | 10 +--- .../attrupdateconfig_flags.go | 11 +++- .../attrupdateconfig_flags_test.go | 10 +--- .../clusterresourceattribute/delete_config.go | 2 +- .../clusterresourceattribute/fetch_config.go | 2 +- .../clusterresourceattribute/update_config.go | 2 +- .../subcommand/execution/config_flags.go | 4 +- .../subcommand/execution/config_flags_test.go | 12 ++--- .../attrdeleteconfig_flags.go | 11 +++- .../attrdeleteconfig_flags_test.go | 10 +--- .../attrfetchconfig_flags.go | 11 +++- .../attrfetchconfig_flags_test.go | 10 +--- .../attrupdateconfig_flags.go | 11 +++- .../attrupdateconfig_flags_test.go | 10 +--- .../executionclusterlabel/delete_config.go | 2 +- .../executionclusterlabel/fetch_config.go | 2 +- .../executionclusterlabel/update_config.go | 2 +- .../attrdeleteconfig_flags.go | 11 +++- .../attrdeleteconfig_flags_test.go | 10 +--- .../attrfetchconfig_flags.go | 11 +++- .../attrfetchconfig_flags_test.go | 10 +--- .../attrupdateconfig_flags.go | 11 +++- .../attrupdateconfig_flags_test.go | 10 +--- .../executionqueueattribute/delete_config.go | 2 +- .../executionqueueattribute/fetch_config.go | 2 +- .../executionqueueattribute/update_config.go | 2 +- .../subcommand/launchplan/config_flags.go | 15 +++--- .../launchplan/config_flags_test.go | 12 ++--- .../launchplan/launchplan_config.go | 2 +- .../plugin_override/attrdeleteconfig_flags.go | 11 +++- .../attrdeleteconfig_flags_test.go | 10 +--- .../plugin_override/attrfetchconfig_flags.go | 11 +++- .../attrfetchconfig_flags_test.go | 10 +--- .../plugin_override/attrupdateconfig_flags.go | 11 +++- .../attrupdateconfig_flags_test.go | 10 +--- .../plugin_override/delete_config.go | 2 +- .../plugin_override/fetch_config.go | 2 +- .../plugin_override/update_config.go | 2 +- .../config/subcommand/project/config_flags.go | 8 +-- .../subcommand/project/config_flags_test.go | 12 ++--- .../subcommand/project/project_config.go | 2 +- .../subcommand/register/filesconfig_flags.go | 49 ++++++++++++++--- .../config/subcommand/sandbox/config_flags.go | 37 +++++++++++++ .../subcommand/sandbox/sandbox_config.go | 2 +- .../config/subcommand/task/config_flags.go | 15 +++--- .../subcommand/task/config_flags_test.go | 12 ++--- .../cmd/config/subcommand/task/task_config.go | 2 +- .../attrdeleteconfig_flags.go | 11 +++- .../attrdeleteconfig_flags_test.go | 10 +--- .../attrfetchconfig_flags.go | 11 +++- .../attrfetchconfig_flags_test.go | 10 +--- .../attrupdateconfig_flags.go | 11 +++- .../attrupdateconfig_flags_test.go | 10 +--- .../taskresourceattribute/delete_config.go | 2 +- .../taskresourceattribute/fetch_config.go | 2 +- .../taskresourceattribute/update_config.go | 2 +- .../subcommand/workflow/config_flags.go | 4 +- .../subcommand/workflow/config_flags_test.go | 12 ++--- flytectl/cmd/create/execution.go | 2 +- flytectl/cmd/create/executionconfig_flags.go | 21 +++++--- .../cmd/create/executionconfig_flags_test.go | 52 +++++-------------- flytectl/cmd/get/execution.go | 4 +- flytectl/cmd/get/launch_plan.go | 6 +-- flytectl/cmd/get/project.go | 4 +- flytectl/cmd/get/task.go | 6 +-- flytectl/cmd/get/workflow.go | 6 +-- flytectl/cmd/register/files.go | 12 ++--- flytectl/cmd/update/named_entity.go | 2 +- .../cmd/update/namedentityconfig_flags.go | 17 ++++-- .../update/namedentityconfig_flags_test.go | 26 +--------- flytectl/cmd/update/project.go | 25 +++------ flytectl/cmd/update/project_test.go | 12 ++--- flytectl/cmd/update/projectconfig_flags.go | 13 ++++- .../cmd/update/projectconfig_flags_test.go | 18 +------ flytectl/cmd/update/update.go | 2 +- .../source/gen/flytectl_get_execution.rst | 18 +++---- .../source/gen/flytectl_get_launchplan.rst | 22 ++++---- .../docs/source/gen/flytectl_get_project.rst | 14 ++--- .../docs/source/gen/flytectl_get_task.rst | 22 ++++---- .../docs/source/gen/flytectl_get_workflow.rst | 20 +++---- .../source/gen/flytectl_register_examples.rst | 10 ++-- .../source/gen/flytectl_register_files.rst | 22 ++++---- .../source/gen/flytectl_update_launchplan.rst | 6 +-- .../source/gen/flytectl_update_project.rst | 21 ++------ .../docs/source/gen/flytectl_update_task.rst | 6 +-- .../source/gen/flytectl_update_workflow.rst | 6 +-- flytectl/pkg/adminutils/config.go | 6 +-- flytectl/pkg/adminutils/config_flags.go | 13 ++++- flytectl/pkg/adminutils/config_flags_test.go | 18 +------ flytectl/pkg/adminutils/config_test.go | 17 ------ flytectl/pkg/filters/type.go | 4 +- 96 files changed, 504 insertions(+), 502 deletions(-) delete mode 100644 flytectl/pkg/adminutils/config_test.go diff --git a/flytectl/cmd/config/config.go b/flytectl/cmd/config/config.go index 6c212d1cf97..d038c316f5f 100644 --- a/flytectl/cmd/config/config.go +++ b/flytectl/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/flytectl/cmd/config/config_flags.go b/flytectl/cmd/config/config_flags.go index 3a1616b7e69..f219394ffbc 100755 --- a/flytectl/cmd/config/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go index 2ee35a78872..447d2e04710 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go index 798e81d2cf6..63cb34732bb 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrdeleteconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go index 477e57689f5..47dfb88623a 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go index 4d8ae3e0e6a..dbcbb814fb8 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrfetchconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go index 60a9af145a5..7b19fc93f42 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go index aa5d18dd077..98569122482 100755 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/attrupdateconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/delete_config.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/delete_config.go index 3b81cd0991f..11120039234 100644 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/delete_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/fetch_config.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/fetch_config.go index 9da6d481f87..88afae90acc 100644 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/fetch_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/clusterresourceattribute/update_config.go b/flytectl/cmd/config/subcommand/clusterresourceattribute/update_config.go index 2ff214af1fb..fcbbe04d2a9 100644 --- a/flytectl/cmd/config/subcommand/clusterresourceattribute/update_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/execution/config_flags.go b/flytectl/cmd/config/subcommand/execution/config_flags.go index 467fbd7f6cd..f9a96f52610 100755 --- a/flytectl/cmd/config/subcommand/execution/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/execution/config_flags_test.go b/flytectl/cmd/config/subcommand/execution/config_flags_test.go index 7fbd9e51f74..88cfd5fca0a 100755 --- a/flytectl/cmd/config/subcommand/execution/config_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go index 3dc56c9837c..bbaa014f794 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go index 02ec1217d1e..2c669643d9a 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrdeleteconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go index 0e1d0d060f8..97bf9e8ff11 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go index a99fd919334..495e5024d65 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrfetchconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go index f2f0d84852b..bb592423db9 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go index ca7e09eb4df..fa011c6c1b5 100755 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/attrupdateconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/delete_config.go b/flytectl/cmd/config/subcommand/executionclusterlabel/delete_config.go index 5a96d6fdfa9..cbd1a09018c 100644 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/delete_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/fetch_config.go b/flytectl/cmd/config/subcommand/executionclusterlabel/fetch_config.go index 8e7f878edeb..68a27ea6fb3 100644 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/fetch_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionclusterlabel/update_config.go b/flytectl/cmd/config/subcommand/executionclusterlabel/update_config.go index abd56005531..ba3e9d3d880 100644 --- a/flytectl/cmd/config/subcommand/executionclusterlabel/update_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go index 15852717ded..d3ab937c615 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go index d42fa0c9c74..46875fd4572 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrdeleteconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go index 0eed381d70c..05a277f93a1 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go index 449b82faae7..73e37ab4475 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrfetchconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go index c858ca34c8a..ffd725ff3e5 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go b/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go index dbe66421657..fafee300fb8 100755 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/attrupdateconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/delete_config.go b/flytectl/cmd/config/subcommand/executionqueueattribute/delete_config.go index a6754eb4f44..48dedc581bc 100644 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/delete_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/fetch_config.go b/flytectl/cmd/config/subcommand/executionqueueattribute/fetch_config.go index 4c5c154f2b3..62a76d6ba1f 100644 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/fetch_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/executionqueueattribute/update_config.go b/flytectl/cmd/config/subcommand/executionqueueattribute/update_config.go index 11b319f1d15..8dd3e595a4c 100644 --- a/flytectl/cmd/config/subcommand/executionqueueattribute/update_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/launchplan/config_flags.go b/flytectl/cmd/config/subcommand/launchplan/config_flags.go index db572d98ea7..e41777eebce 100755 --- a/flytectl/cmd/config/subcommand/launchplan/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go b/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go index ec536464bce..d2ccb2715d9 100755 --- a/flytectl/cmd/config/subcommand/launchplan/config_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/launchplan/launchplan_config.go b/flytectl/cmd/config/subcommand/launchplan/launchplan_config.go index 5e245deb48b..7c8245256a1 100644 --- a/flytectl/cmd/config/subcommand/launchplan/launchplan_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go b/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go index 52fd144b99b..7003e5e1ddb 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go b/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go index 7a5d60873c0..01290735163 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrdeleteconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go b/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go index 1cf522b3ca4..e7c79a92b40 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go b/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go index e94f54e9820..d5206f1d330 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrfetchconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go b/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go index 21c58dbb9d4..1edf6828799 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go b/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go index 37ee0382c1b..c23184f43bc 100755 --- a/flytectl/cmd/config/subcommand/plugin_override/attrupdateconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/delete_config.go b/flytectl/cmd/config/subcommand/plugin_override/delete_config.go index beec54fd95a..de00f5cf7f7 100644 --- a/flytectl/cmd/config/subcommand/plugin_override/delete_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/fetch_config.go b/flytectl/cmd/config/subcommand/plugin_override/fetch_config.go index 9976d8b33f3..e2283e7c80c 100644 --- a/flytectl/cmd/config/subcommand/plugin_override/fetch_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/plugin_override/update_config.go b/flytectl/cmd/config/subcommand/plugin_override/update_config.go index e2daefa8f3e..aa0d9af0b21 100644 --- a/flytectl/cmd/config/subcommand/plugin_override/update_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/project/config_flags.go b/flytectl/cmd/config/subcommand/project/config_flags.go index 3a3e9bb5df1..ca18dca6305 100755 --- a/flytectl/cmd/config/subcommand/project/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/project/config_flags_test.go b/flytectl/cmd/config/subcommand/project/config_flags_test.go index 50fcfad9d25..52668bcf146 100755 --- a/flytectl/cmd/config/subcommand/project/config_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/project/project_config.go b/flytectl/cmd/config/subcommand/project/project_config.go index e5a78505952..8692a746cd7 100644 --- a/flytectl/cmd/config/subcommand/project/project_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/register/filesconfig_flags.go b/flytectl/cmd/config/subcommand/register/filesconfig_flags.go index a28aead6e51..9ddea3a5470 100755 --- a/flytectl/cmd/config/subcommand/register/filesconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/sandbox/config_flags.go b/flytectl/cmd/config/subcommand/sandbox/config_flags.go index ebecc0a5b9d..b727f8a04dc 100755 --- a/flytectl/cmd/config/subcommand/sandbox/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go b/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go index afe85beddf7..833a950495a 100644 --- a/flytectl/cmd/config/subcommand/sandbox/sandbox_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/task/config_flags.go b/flytectl/cmd/config/subcommand/task/config_flags.go index 4c48a38e6c3..31384390178 100755 --- a/flytectl/cmd/config/subcommand/task/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/task/config_flags_test.go b/flytectl/cmd/config/subcommand/task/config_flags_test.go index bea2ff142e0..844d031a5a2 100755 --- a/flytectl/cmd/config/subcommand/task/config_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/task/task_config.go b/flytectl/cmd/config/subcommand/task/task_config.go index 241a1c1faba..1e0d6a2bec1 100644 --- a/flytectl/cmd/config/subcommand/task/task_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go index b335257d99c..d1128e5e9e1 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go index 3c219496aeb..f41f531f3fc 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrdeleteconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go index 761baa5c3a8..0efc3387689 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go index 1b91152a970..038f8a893c9 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrfetchconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go index b94b102bc66..e57de741e75 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go b/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go index 2672552de42..06f17f631ca 100755 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/attrupdateconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/delete_config.go b/flytectl/cmd/config/subcommand/taskresourceattribute/delete_config.go index 6c513cafe06..6d88a180a7c 100644 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/delete_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/fetch_config.go b/flytectl/cmd/config/subcommand/taskresourceattribute/fetch_config.go index 6909229c304..1fe6de9937b 100644 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/fetch_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/taskresourceattribute/update_config.go b/flytectl/cmd/config/subcommand/taskresourceattribute/update_config.go index d9ea24ab771..2dd2451e9c6 100644 --- a/flytectl/cmd/config/subcommand/taskresourceattribute/update_config.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/workflow/config_flags.go b/flytectl/cmd/config/subcommand/workflow/config_flags.go index 5765379fe61..29bc7fca546 100755 --- a/flytectl/cmd/config/subcommand/workflow/config_flags.go +++ b/flytectl/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/flytectl/cmd/config/subcommand/workflow/config_flags_test.go b/flytectl/cmd/config/subcommand/workflow/config_flags_test.go index 86998d77885..4011d8e4f39 100755 --- a/flytectl/cmd/config/subcommand/workflow/config_flags_test.go +++ b/flytectl/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/flytectl/cmd/create/execution.go b/flytectl/cmd/create/execution.go index f765e786b29..4fdea5214d9 100644 --- a/flytectl/cmd/create/execution.go +++ b/flytectl/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/flytectl/cmd/create/executionconfig_flags.go b/flytectl/cmd/create/executionconfig_flags.go index 974c284b0be..5fb13bbbe88 100755 --- a/flytectl/cmd/create/executionconfig_flags.go +++ b/flytectl/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/flytectl/cmd/create/executionconfig_flags_test.go b/flytectl/cmd/create/executionconfig_flags_test.go index bf7ab9c47b8..9e35676125d 100755 --- a/flytectl/cmd/create/executionconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/get/execution.go b/flytectl/cmd/get/execution.go index f5477893494..2e8232ca7e0 100644 --- a/flytectl/cmd/get/execution.go +++ b/flytectl/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/flytectl/cmd/get/launch_plan.go b/flytectl/cmd/get/launch_plan.go index 9edff6ab920..ec90a62fd2f 100644 --- a/flytectl/cmd/get/launch_plan.go +++ b/flytectl/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/flytectl/cmd/get/project.go b/flytectl/cmd/get/project.go index 4d13950e1e5..10148a1c07a 100644 --- a/flytectl/cmd/get/project.go +++ b/flytectl/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/flytectl/cmd/get/task.go b/flytectl/cmd/get/task.go index e25206a55f7..49c586f4338 100644 --- a/flytectl/cmd/get/task.go +++ b/flytectl/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/flytectl/cmd/get/workflow.go b/flytectl/cmd/get/workflow.go index 4174f96c1a6..8fba30d2cd5 100644 --- a/flytectl/cmd/get/workflow.go +++ b/flytectl/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/flytectl/cmd/register/files.go b/flytectl/cmd/register/files.go index d758adce98c..210bb1bba2d 100644 --- a/flytectl/cmd/register/files.go +++ b/flytectl/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/flytectl/cmd/update/named_entity.go b/flytectl/cmd/update/named_entity.go index 5c3391d708b..da5380554ec 100644 --- a/flytectl/cmd/update/named_entity.go +++ b/flytectl/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/flytectl/cmd/update/namedentityconfig_flags.go b/flytectl/cmd/update/namedentityconfig_flags.go index 3d61711bec1..e1bd6813415 100755 --- a/flytectl/cmd/update/namedentityconfig_flags.go +++ b/flytectl/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/flytectl/cmd/update/namedentityconfig_flags_test.go b/flytectl/cmd/update/namedentityconfig_flags_test.go index 1f9506481b2..528f913d63a 100755 --- a/flytectl/cmd/update/namedentityconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/update/project.go b/flytectl/cmd/update/project.go index 0a1f5415d73..86d7bb616a9 100644 --- a/flytectl/cmd/update/project.go +++ b/flytectl/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/flytectl/cmd/update/project_test.go b/flytectl/cmd/update/project_test.go index e3eac5ff843..9db9f8cf46f 100644 --- a/flytectl/cmd/update/project_test.go +++ b/flytectl/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/flytectl/cmd/update/projectconfig_flags.go b/flytectl/cmd/update/projectconfig_flags.go index f56579fe9f5..2139fb05634 100755 --- a/flytectl/cmd/update/projectconfig_flags.go +++ b/flytectl/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/flytectl/cmd/update/projectconfig_flags_test.go b/flytectl/cmd/update/projectconfig_flags_test.go index 4a13ad3aff1..c6bc6b262cc 100755 --- a/flytectl/cmd/update/projectconfig_flags_test.go +++ b/flytectl/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/flytectl/cmd/update/update.go b/flytectl/cmd/update/update.go index 34ab70c21c9..8485f320438 100644 --- a/flytectl/cmd/update/update.go +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_get_execution.rst b/flytectl/docs/source/gen/flytectl_get_execution.rst index 174ba886614..e81e77ac7ca 100644 --- a/flytectl/docs/source/gen/flytectl_get_execution.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_get_launchplan.rst b/flytectl/docs/source/gen/flytectl_get_launchplan.rst index f50798c59c5..51c936f2648 100644 --- a/flytectl/docs/source/gen/flytectl_get_launchplan.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_get_project.rst b/flytectl/docs/source/gen/flytectl_get_project.rst index 7aafa4e606a..541f9e9a2d8 100644 --- a/flytectl/docs/source/gen/flytectl_get_project.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_get_task.rst b/flytectl/docs/source/gen/flytectl_get_task.rst index c94f945b186..49148043bba 100644 --- a/flytectl/docs/source/gen/flytectl_get_task.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_get_workflow.rst b/flytectl/docs/source/gen/flytectl_get_workflow.rst index 63a55c3a4e6..6c8ec191953 100644 --- a/flytectl/docs/source/gen/flytectl_get_workflow.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_register_examples.rst b/flytectl/docs/source/gen/flytectl_register_examples.rst index 1a32690879f..b1929fc1ea6 100644 --- a/flytectl/docs/source/gen/flytectl_register_examples.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_register_files.rst b/flytectl/docs/source/gen/flytectl_register_files.rst index 2e3207d832b..55e8bab2bb9 100644 --- a/flytectl/docs/source/gen/flytectl_register_files.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_update_launchplan.rst b/flytectl/docs/source/gen/flytectl_update_launchplan.rst index 9c98daa2eff..0bc98036df0 100644 --- a/flytectl/docs/source/gen/flytectl_update_launchplan.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_update_project.rst b/flytectl/docs/source/gen/flytectl_update_project.rst index e7b46654480..437df1e0cd0 100644 --- a/flytectl/docs/source/gen/flytectl_update_project.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_update_task.rst b/flytectl/docs/source/gen/flytectl_update_task.rst index 954071ee2a1..f82ef9a7a12 100644 --- a/flytectl/docs/source/gen/flytectl_update_task.rst +++ b/flytectl/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/flytectl/docs/source/gen/flytectl_update_workflow.rst b/flytectl/docs/source/gen/flytectl_update_workflow.rst index 14f28a40820..b9d9abc384f 100644 --- a/flytectl/docs/source/gen/flytectl_update_workflow.rst +++ b/flytectl/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/flytectl/pkg/adminutils/config.go b/flytectl/pkg/adminutils/config.go index f47ae8276ba..71f0a3f4766 100644 --- a/flytectl/pkg/adminutils/config.go +++ b/flytectl/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/flytectl/pkg/adminutils/config_flags.go b/flytectl/pkg/adminutils/config_flags.go index 5a3c9a2c4d7..f62caa371ce 100755 --- a/flytectl/pkg/adminutils/config_flags.go +++ b/flytectl/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/flytectl/pkg/adminutils/config_flags_test.go b/flytectl/pkg/adminutils/config_flags_test.go index 1f7cf5ec736..de285339d13 100755 --- a/flytectl/pkg/adminutils/config_flags_test.go +++ b/flytectl/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/flytectl/pkg/adminutils/config_test.go b/flytectl/pkg/adminutils/config_test.go deleted file mode 100644 index 5a8fd5134d1..00000000000 --- a/flytectl/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/flytectl/pkg/filters/type.go b/flytectl/pkg/filters/type.go index 5dbad769237..6dabc0904d7 100644 --- a/flytectl/pkg/filters/type.go +++ b/flytectl/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"`