Skip to content

Commit 03eb272

Browse files
committed
cmd: use SetIndent(2) to dump yaml subcommands
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
1 parent 263902a commit 03eb272

File tree

14 files changed

+76
-75
lines changed

14 files changed

+76
-75
lines changed

cmd/admin.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func newAdminCommand(config *settings.Config) *cobra.Command {
2525
Args: cobra.MinimumNArgs(1),
2626
}
2727
importOrbCommand.Flags().BoolVar(&orbOpts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
28-
if err := importOrbCommand.Flags().MarkHidden("integration-testing"); err != nil {
29-
panic(err)
30-
}
28+
// if err := importOrbCommand.Flags().MarkHidden("integration-testing"); err != nil {
29+
// panic(err)
30+
// }
3131
importOrbCommand.Flags().BoolVar(&orbOpts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI.")
3232

3333
renameCommand := &cobra.Command{
@@ -79,9 +79,9 @@ Example:
7979
deleteAliasCommand.Annotations["<name>"] = "The name of the alias to delete"
8080
deleteAliasCommand.Flags().BoolVar(&nsOpts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI.")
8181
deleteAliasCommand.Flags().BoolVar(&nsOpts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
82-
if err := deleteAliasCommand.Flags().MarkHidden("integration-testing"); err != nil {
83-
panic(err)
84-
}
82+
// if err := deleteAliasCommand.Flags().MarkHidden("integration-testing"); err != nil {
83+
// panic(err)
84+
// }
8585

8686
deleteNamespaceCommand := &cobra.Command{
8787
Use: "delete-namespace <name>",
@@ -110,7 +110,7 @@ Example:
110110

111111
adminCommand := &cobra.Command{
112112
Use: "admin",
113-
Short: "Administrative operations for a CircleCI Server installation.",
113+
Short: "Administrative operations for a CircleCI Server installation. (hidden)",
114114
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
115115
orbOpts.args = args
116116
nsOpts.args = args
@@ -122,7 +122,7 @@ Example:
122122
// As of writing this comment, that is only for daily update checks.
123123
return rootCmdPreRun(rootOptions)
124124
},
125-
Hidden: true,
125+
Hidden: false,
126126
}
127127

128128
adminCommand.AddCommand(importOrbCommand)

cmd/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func newLocalExecuteCommand(config *settings.Config) *cobra.Command {
2424
// hidden command for backwards compatibility
2525
func newBuildCommand(config *settings.Config) *cobra.Command {
2626
cmd := newLocalExecuteCommand(config)
27-
cmd.Hidden = true
28-
cmd.Use = "build"
27+
cmd.Hidden = false
28+
cmd.Use = "build (hidden)"
2929
return cmd
3030
}
3131

cmd/config.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"io/ioutil"
6+
"strings"
67

78
"github.com/CircleCI-Public/circleci-cli/api"
89
"github.com/CircleCI-Public/circleci-cli/api/graphql"
@@ -73,9 +74,6 @@ func newConfigCommand(config *settings.Config) *cobra.Command {
7374
validateCommand.Annotations["<path>"] = configAnnotations["<path>"]
7475
validateCommand.PersistentFlags().StringVarP(&configPath, "config", "c", ".circleci/config.yml", "path to config file")
7576
validateCommand.PersistentFlags().BoolVar(&ignoreDeprecatedImages, "ignore-deprecated-images", false, "ignores the deprecated images error")
76-
if err := validateCommand.PersistentFlags().MarkHidden("config"); err != nil {
77-
panic(err)
78-
}
7977
validateCommand.Flags().StringP("org-slug", "o", "", "organization slug (for example: github/example-org), used when a config depends on private orbs belonging to that org")
8078

8179
processCommand := &cobra.Command{
@@ -97,14 +95,13 @@ func newConfigCommand(config *settings.Config) *cobra.Command {
9795

9896
migrateCommand := &cobra.Command{
9997
Use: "migrate",
100-
Short: "Migrate a pre-release 2.0 config to the official release version",
98+
Short: "Migrate a pre-release 2.0 config to the official release version (hidden)",
10199
PreRun: func(cmd *cobra.Command, args []string) {
102100
opts.args = args
103101
},
104102
RunE: func(_ *cobra.Command, _ []string) error {
105103
return migrateConfig(opts)
106104
},
107-
Hidden: true,
108105
DisableFlagParsing: true,
109106
}
110107
// These flags are for documentation and not actually parsed
@@ -193,11 +190,13 @@ func packConfig(opts configOptions) error {
193190
return errors.Wrap(err, "An error occurred trying to build the tree")
194191
}
195192

196-
y, err := yaml.Marshal(&tree)
197-
if err != nil {
193+
var s strings.Builder
194+
enc := yaml.NewEncoder(&s)
195+
enc.SetIndent(2)
196+
if err := enc.Encode(&tree); err != nil {
198197
return errors.Wrap(err, "Failed trying to marshal the tree to YAML ")
199198
}
200-
fmt.Printf("%s\n", string(y))
199+
fmt.Print(s.String())
201200
return nil
202201
}
203202

cmd/namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Please note that at this time all namespaces created in the registry are world-r
8282
createCmd.Annotations["<vcs-type>"] = `Your VCS provider, can be either "github" or "bitbucket"`
8383
createCmd.Annotations["<org-name>"] = `The name used for your organization`
8484

85-
createCmd.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
85+
createCmd.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI. (hidden)")
8686
if err := createCmd.Flags().MarkHidden("integration-testing"); err != nil {
8787
panic(err)
8888
}

cmd/orb.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ func newOrbCommand(config *settings.Config) *cobra.Command {
102102

103103
listCommand.PersistentFlags().StringVar(&opts.sortBy, "sort", "", `one of "builds"|"projects"|"orgs"`)
104104
listCommand.PersistentFlags().BoolVarP(&opts.listUncertified, "uncertified", "u", false, "include uncertified orbs")
105-
listCommand.PersistentFlags().BoolVar(&opts.listJSON, "json", false, "print output as json instead of human-readable")
105+
listCommand.PersistentFlags().BoolVar(&opts.listJSON, "json", false, "print output as json instead of human-readable (hidden)")
106106
listCommand.PersistentFlags().BoolVarP(&opts.listDetails, "details", "d", false, "output all the commands, executors, and jobs, along with a tree of their parameters")
107107
listCommand.PersistentFlags().BoolVarP(&opts.private, "private", "", false, "exclusively list private orbs within a namespace")
108-
if err := listCommand.PersistentFlags().MarkHidden("json"); err != nil {
109-
panic(err)
110-
}
108+
// if err := listCommand.PersistentFlags().MarkHidden("json"); err != nil {
109+
// panic(err)
110+
// }
111111

112112
validateCommand := &cobra.Command{
113113
Use: "validate <path>",
@@ -285,10 +285,10 @@ Please note that at this time all orbs created in the registry are world-readabl
285285
},
286286
}
287287

288-
listCategoriesCommand.PersistentFlags().BoolVar(&opts.listJSON, "json", false, "print output as json instead of human-readable")
289-
if err := listCategoriesCommand.PersistentFlags().MarkHidden("json"); err != nil {
290-
panic(err)
291-
}
288+
listCategoriesCommand.PersistentFlags().BoolVar(&opts.listJSON, "json", false, "print output as json instead of human-readable (hidden)")
289+
// if err := listCategoriesCommand.PersistentFlags().MarkHidden("json"); err != nil {
290+
// panic(err)
291+
// }
292292

293293
addCategorizationToOrbCommand := &cobra.Command{
294294
Use: "add-to-category <namespace>/<orb> \"<category-name>\"",
@@ -319,10 +319,10 @@ Please note that at this time all orbs created in the registry are world-readabl
319319
}
320320
orbInit.PersistentFlags().BoolVarP(&opts.private, "private", "", false, "initialize a private orb")
321321

322-
orbCreate.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
323-
if err := orbCreate.Flags().MarkHidden("integration-testing"); err != nil {
324-
panic(err)
325-
}
322+
orbCreate.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI. (hidden)")
323+
// if err := orbCreate.Flags().MarkHidden("integration-testing"); err != nil {
324+
// panic(err)
325+
// }
326326
orbCreate.Flags().BoolVar(&opts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI.")
327327

328328
orbCommand := &cobra.Command{
@@ -987,13 +987,15 @@ func packOrb(path string) (string, error) {
987987
return "", errors.Wrap(err, "An unexpected error occurred")
988988
}
989989

990-
y, err := yaml.Marshal(&tree)
991-
if err != nil {
990+
var buf bytes.Buffer
991+
enc := yaml.NewEncoder(&buf)
992+
enc.SetIndent(2)
993+
if err := enc.Encode(&tree); err != nil {
992994
return "", errors.Wrap(err, "An unexpected error occurred")
993995
}
994996

995997
var orbSchema OrbSchema
996-
err = yaml.Unmarshal(y, &orbSchema)
998+
err = yaml.Unmarshal(buf.Bytes(), &orbSchema)
997999
if err != nil {
9981000
return "", errors.Wrap(err, "An unexpected error occurred")
9991001
}
@@ -1011,12 +1013,12 @@ func packOrb(path string) (string, error) {
10111013
return "", err
10121014
}
10131015

1014-
final, err := yaml.Marshal(&orbSchema)
1015-
if err != nil {
1016+
buf.Reset()
1017+
if err := enc.Encode(&orbSchema); err != nil {
10161018
return "", errors.Wrap(err, "Failed trying to marshal Orb YAML")
10171019
}
10181020

1019-
return string(final), nil
1021+
return buf.String(), nil
10201022
}
10211023

10221024
// Travel down a YAML node, replacing values as we go.

cmd/orb_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,11 +3332,11 @@ Windows Server 2010
33323332
Expect(err).ShouldNot(HaveOccurred())
33333333

33343334
Eventually(session.Out).Should(gbytes.Say(`commands:
3335-
orb:
3336-
steps:
3337-
- run:
3338-
command: echo Hello, world!
3339-
name: Say hello
3335+
orb:
3336+
steps:
3337+
- run:
3338+
command: echo Hello, world!
3339+
name: Say hello
33403340
`))
33413341
Eventually(session).Should(gexec.Exit(0))
33423342
})

cmd/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func newQueryCommand(config *settings.Config) *cobra.Command {
2525

2626
queryCommand := &cobra.Command{
2727
Use: "query <path>",
28-
Short: "Query the CircleCI GraphQL API.",
29-
Hidden: true,
28+
Short: "Query the CircleCI GraphQL API. (hidden)",
29+
Hidden: false,
3030
PreRunE: func(_ *cobra.Command, args []string) error {
3131
opts.args = args
3232
opts.cl = graphql.NewClient(config.HTTPClient, config.Host, config.Endpoint, config.Token, config.Debug)

cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ func MakeCommands() *cobra.Command {
158158

159159
flags := rootCmd.PersistentFlags()
160160

161-
flags.BoolVar(&rootOptions.Debug, "debug", rootOptions.Debug, "Enable debug logging.")
161+
flags.BoolVar(&rootOptions.Debug, "debug", rootOptions.Debug, "Enable debug logging. (hidden)")
162162
flags.StringVar(&rootTokenFromFlag, "token", "", "your token for using CircleCI, also CIRCLECI_CLI_TOKEN")
163163
flags.StringVar(&rootOptions.Host, "host", rootOptions.Host, "URL to your CircleCI host, also CIRCLECI_CLI_HOST")
164-
flags.StringVar(&rootOptions.Endpoint, "endpoint", rootOptions.Endpoint, "URI to your CircleCI GraphQL API endpoint")
165-
flags.StringVar(&rootOptions.GitHubAPI, "github-api", "https://api.github.com/", "Change the default endpoint to GitHub API for retrieving updates")
164+
flags.StringVar(&rootOptions.Endpoint, "endpoint", rootOptions.Endpoint, "URI to your CircleCI GraphQL API endpoint (hidden)")
165+
flags.StringVar(&rootOptions.GitHubAPI, "github-api", "https://api.github.com/", "Change the default endpoint to GitHub API for retrieving updates (hidden)")
166166
flags.BoolVar(&rootOptions.SkipUpdateCheck, "skip-update-check", skipUpdateByDefault(), "Skip the check for updates check run before every command.")
167167

168168
hidden := []string{"github-api", "debug", "endpoint"}

cmd/setup.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ func newSetupCommand(config *settings.Config) *cobra.Command {
141141
},
142142
}
143143

144-
setupCommand.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
145-
if err := setupCommand.Flags().MarkHidden("integration-testing"); err != nil {
146-
panic(err)
147-
}
144+
setupCommand.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI. (hidden)")
145+
// if err := setupCommand.Flags().MarkHidden("integration-testing"); err != nil {
146+
// panic(err)
147+
// }
148148

149149
setupCommand.Flags().BoolVar(&opts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI. (MUST supply --host and --token)")
150150

151-
setupCommand.Flags().StringVar(&opts.host, "host", "", "URL to your CircleCI host")
152-
if err := setupCommand.Flags().MarkHidden("host"); err != nil {
153-
panic(err)
154-
}
151+
setupCommand.Flags().StringVar(&opts.host, "host", "", "URL to your CircleCI host (hidden)")
152+
// if err := setupCommand.Flags().MarkHidden("host"); err != nil {
153+
// panic(err)
154+
// }
155155

156-
setupCommand.Flags().StringVar(&opts.token, "token", "", "your token for using CircleCI")
157-
if err := setupCommand.Flags().MarkHidden("token"); err != nil {
158-
panic(err)
159-
}
156+
setupCommand.Flags().StringVar(&opts.token, "token", "", "your token for using CircleCI (hidden)")
157+
// if err := setupCommand.Flags().MarkHidden("token"); err != nil {
158+
// panic(err)
159+
// }
160160

161161
return setupCommand
162162
}

cmd/step.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ func newStepCommand(config *settings.Config) *cobra.Command {
1818

1919
stepCmd := &cobra.Command{
2020
Use: "step",
21-
Short: "Execute steps",
22-
Hidden: true,
21+
Short: "Execute steps (hidden)",
22+
Hidden: false,
2323
DisableFlagParsing: true,
2424
}
2525

2626
haltCmd := &cobra.Command{
2727
Use: "halt",
28-
Short: "Halt the current job and treat it as successful",
28+
Short: "Halt the current job and treat it as successful (hidden)",
2929
PreRun: func(cmd *cobra.Command, args []string) {
3030
opts.args = args
3131
},
3232
RunE: func(_ *cobra.Command, _ []string) error {
3333
return haltRunE(opts)
3434
},
35-
Hidden: true,
35+
Hidden: false,
3636
DisableFlagParsing: true,
3737
}
3838

0 commit comments

Comments
 (0)