Skip to content

Commit 33d2c5c

Browse files
authored
cmd: Remove sdkcmdutil.FileOrStdin use (#337)
Using the `sdkcmdutil.FileOrStdin` does not work well when coupled with Ansible since it thinks the Stdin is always populated even when not. Last, Removes required flag since stdin can be populated. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent 21c5b18 commit 33d2c5c

File tree

6 files changed

+0
-30
lines changed

6 files changed

+0
-30
lines changed

cmd/deployment/create.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ var createCmd = &cobra.Command{
6969
var skipFlagBased = cmd.Flag("deployment-template").Hidden
7070

7171
var payload *models.DeploymentCreateRequest
72-
if err := sdkcmdutil.FileOrStdin(cmd, "file"); err != nil && skipFlagBased {
73-
return err
74-
}
7572

7673
err := sdkcmdutil.DecodeDefinition(cmd, "file", &payload)
7774
if err := returnErrOnHidden(err, skipFlagBased); err != nil {
@@ -166,7 +163,6 @@ func init() {
166163
Command.AddCommand(createCmd)
167164
createCmd.Flags().StringP("file", "f", "", "DeploymentCreateRequest file definition. See help for more information")
168165
// Remove when reads for deployment templates are available on ESS
169-
createCmd.MarkFlagRequired("file")
170166
createCmd.Flags().String("deployment-template", "default", "Deployment template ID on which to base the deployment from")
171167
createCmd.Flags().String("version", "", "Version to use, if not specified, the latest available stack version will be used")
172168
createCmd.Flags().String("name", "", "Optional name for the deployment")

cmd/platform/deployment-template/create.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/configurationtemplateapi"
24-
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2524
"github.com/spf13/cobra"
2625

2726
"github.com/elastic/ecctl/pkg/ecctl"
@@ -32,10 +31,6 @@ var createCmd = &cobra.Command{
3231
Short: "Creates a platform deployment template",
3332
PreRunE: cobra.NoArgs,
3433
RunE: func(cmd *cobra.Command, args []string) error {
35-
if err := sdkcmdutil.FileOrStdin(cmd, "file-template"); err != nil {
36-
return err
37-
}
38-
3934
tc, err := parseTemplateFile(cmd.Flag("file-template").Value.String())
4035
if err != nil {
4136
return err

cmd/platform/deployment-template/update.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/configurationtemplateapi"
24-
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2524
"github.com/spf13/cobra"
2625

2726
"github.com/elastic/ecctl/pkg/ecctl"
@@ -32,9 +31,6 @@ var updateCmd = &cobra.Command{
3231
Short: "Updates a platform deployment template",
3332
PreRunE: cobra.ExactArgs(1),
3433
RunE: func(cmd *cobra.Command, args []string) error {
35-
if err := sdkcmdutil.FileOrStdin(cmd, "file-template"); err != nil {
36-
return err
37-
}
3834
tc, err := parseTemplateFile(cmd.Flag("file-template").Value.String())
3935
if err != nil {
4036
return err

cmd/platform/instance-configuration/create.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/instanceconfigapi"
2525
"github.com/elastic/cloud-sdk-go/pkg/input"
26-
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2726
"github.com/spf13/cobra"
2827

2928
"github.com/elastic/ecctl/pkg/ecctl"
@@ -34,10 +33,6 @@ var createCmd = &cobra.Command{
3433
Short: "Creates a new instance configuration",
3534
PreRunE: cobra.NoArgs,
3635
RunE: func(cmd *cobra.Command, args []string) error {
37-
if err := sdkcmdutil.FileOrStdin(cmd, "file"); err != nil {
38-
return err
39-
}
40-
4136
file, err := input.NewFileOrReader(os.Stdin, cmd.Flag("file").Value.String())
4237
if err != nil {
4338
return err
@@ -72,5 +67,4 @@ func init() {
7267

7368
createCmd.Flags().StringP("file", "f", "", "Instance configuration JSON file definition")
7469
createCmd.Flags().String("id", "", "Optional ID to set for the instance configuration (Overrides id if present)")
75-
createCmd.MarkFlagRequired("file")
7670
}

cmd/platform/instance-configuration/update.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/instanceconfigapi"
2424
"github.com/elastic/cloud-sdk-go/pkg/input"
25-
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2625
"github.com/spf13/cobra"
2726

2827
"github.com/elastic/ecctl/pkg/ecctl"
@@ -33,10 +32,6 @@ var updateCmd = &cobra.Command{
3332
Short: "Overwrites an instance configuration",
3433
PreRunE: cobra.ExactArgs(1),
3534
RunE: func(cmd *cobra.Command, args []string) error {
36-
if err := sdkcmdutil.FileOrStdin(cmd, "file"); err != nil {
37-
return err
38-
}
39-
4035
file, err := input.NewFileOrReader(os.Stdin, cmd.Flag("file").Value.String())
4136
if err != nil {
4237
return err
@@ -61,5 +56,4 @@ func init() {
6156
Command.AddCommand(updateCmd)
6257

6358
updateCmd.Flags().StringP("file", "f", "", "Instance configuration JSON file definition")
64-
updateCmd.MarkFlagRequired("file")
6559
}

cmd/platform/repository/create.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/snaprepoapi"
2626
"github.com/elastic/cloud-sdk-go/pkg/input"
27-
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2827
"github.com/spf13/cobra"
2928

3029
"github.com/elastic/ecctl/pkg/ecctl"
@@ -77,10 +76,6 @@ func setSnapshot(cmd *cobra.Command, args []string) error {
7776
}
7877
}
7978

80-
if err := sdkcmdutil.FileOrStdin(cmd, "settings"); err != nil {
81-
return err
82-
}
83-
8479
f, err := input.NewFileOrReader(os.Stdin, configFile)
8580
if err != nil {
8681
return err

0 commit comments

Comments
 (0)