Skip to content

Commit 8f8b0cf

Browse files
committed
Simplify list commands
1 parent 4dee07a commit 8f8b0cf

File tree

5 files changed

+63
-223
lines changed

5 files changed

+63
-223
lines changed

commands/list_formatters.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (f *TXTListFormatter) Format(list *List, cnf *config.Config) ([]byte, error
7272
if len(cmd.Aliases) > 0 {
7373
name = name + " (" + strings.Join(cmd.Aliases, ", ") + ")"
7474
}
75-
fmt.Fprintf(writer, " %s\t%s\n", name, cmd.Description.String())
75+
fmt.Fprintf(writer, " %s\t%s\n", name, cmd.Description)
7676
}
7777
}
7878
writer.Flush()
@@ -86,7 +86,7 @@ func (f *RawListFormatter) Format(list *List, _ *config.Config) ([]byte, error)
8686
var b bytes.Buffer
8787
writer := tabwriter.NewWriter(&b, 0, 8, 16, ' ', 0)
8888
for _, cmd := range list.Commands {
89-
fmt.Fprintf(writer, "%s\t%s\n", cmd.Name.String(), cmd.Description.String())
89+
fmt.Fprintf(writer, "%s\t%s\n", cmd.Name.String(), cmd.Description)
9090
}
9191
writer.Flush()
9292

@@ -122,7 +122,7 @@ func (f *MDListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)
122122

123123
for _, cmd := range list.Commands {
124124
b.H2(md.Code(cmd.Name.String()))
125-
b.Paragraph(cmd.Description.String()).Ln()
125+
b.Paragraph(cmd.Description).Ln()
126126

127127
if len(cmd.Aliases) > 0 {
128128
aliases := make([]string, 0, len(cmd.Aliases))
@@ -141,13 +141,12 @@ func (f *MDListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)
141141
}
142142

143143
if cmd.Help != "" {
144-
b.Paragraph(cmd.Help.String()).Ln()
144+
b.Paragraph(cmd.Help).Ln()
145145
}
146146

147-
if cmd.Definition.Arguments != nil && cmd.Definition.Arguments.Len() > 0 {
147+
if len(cmd.Definition.Arguments) > 0 {
148148
b.H4("Arguments")
149-
for pair := cmd.Definition.Arguments.Oldest(); pair != nil; pair = pair.Next() {
150-
arg := pair.Value
149+
for _, arg := range cmd.Definition.Arguments {
151150
line := md.Code(arg.Name)
152151
opts := make([]string, 0, 2)
153152
if arg.IsRequired {
@@ -162,15 +161,14 @@ func (f *MDListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)
162161

163162
b.ListItem(line)
164163
if arg.Description != "" {
165-
b.Paragraph(" " + arg.Description.String()).Ln()
164+
b.Paragraph(" " + arg.Description).Ln()
166165
}
167166
}
168167
}
169168

170-
if cmd.Definition.Options != nil && cmd.Definition.Options.Len() > 0 {
169+
if len(cmd.Definition.Options) > 0 {
171170
b.H4("Options")
172-
for pair := cmd.Definition.Options.Oldest(); pair != nil; pair = pair.Next() {
173-
opt := pair.Value
171+
for _, opt := range cmd.Definition.Options {
174172
line := md.Code(opt.Name)
175173
if opt.Shortcut != "" {
176174
line += " (" + md.Code(opt.Shortcut) + ")"
@@ -180,15 +178,15 @@ func (f *MDListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)
180178
}
181179
b.ListItem(line)
182180
if opt.Description != "" {
183-
b.Paragraph(" " + opt.Description.String()).Ln()
181+
b.Paragraph(" " + opt.Description).Ln()
184182
}
185183
}
186184
}
187185

188186
if len(cmd.Examples) > 0 {
189187
b.H3("Examples")
190188
for _, example := range cmd.Examples {
191-
b.ListItem(example.Description.String() + ":")
189+
b.ListItem(example.Description + ":")
192190
b.CodeBlock(cnf.Application.Executable + " " + cmd.Name.String() + " " + example.Commandline).Ln()
193191
}
194192
}

commands/list_input_options.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package commands
33
import (
44
"fmt"
55

6-
"github.com/fatih/color"
7-
86
"github.com/platformsh/cli/internal/config"
97
)
108

@@ -29,10 +27,10 @@ func NoInteractionOption(cnf *config.Config) Option {
2927
AcceptValue: false,
3028
IsValueRequired: false,
3129
IsMultiple: false,
32-
Description: CleanString("Do not ask any interactive questions; accept default values. " +
30+
Description: "Do not ask any interactive questions; accept default values. " +
3331
"Equivalent to using the environment variable: " +
34-
color.YellowString(fmt.Sprintf("%sNO_INTERACTION=1", cnf.Application.EnvPrefix))),
35-
Default: Any{false},
32+
fmt.Sprintf("%sNO_INTERACTION=1", cnf.Application.EnvPrefix),
33+
Default: false,
3634
Hidden: false,
3735
}
3836
}
@@ -45,7 +43,7 @@ var (
4543
IsValueRequired: false,
4644
IsMultiple: false,
4745
Description: "Display this help message",
48-
Default: Any{false},
46+
Default: false,
4947
Hidden: false,
5048
}
5149
VerboseOption = Option{
@@ -55,7 +53,7 @@ var (
5553
IsValueRequired: false,
5654
IsMultiple: false,
5755
Description: "Increase the verbosity of messages",
58-
Default: Any{false},
56+
Default: false,
5957
Hidden: false,
6058
}
6159
VersionOption = Option{
@@ -65,7 +63,7 @@ var (
6563
IsValueRequired: false,
6664
IsMultiple: false,
6765
Description: "Display this application version",
68-
Default: Any{false},
66+
Default: false,
6967
Hidden: false,
7068
}
7169
YesOption = Option{
@@ -76,7 +74,7 @@ var (
7674
IsMultiple: false,
7775
Description: "Answer \"yes\" to confirmation questions; " +
7876
"accept the default value for other questions; disable interaction",
79-
Default: Any{false},
77+
Default: false,
8078
Hidden: false,
8179
}
8280
AnsiOption = Option{
@@ -86,7 +84,7 @@ var (
8684
IsValueRequired: false,
8785
IsMultiple: false,
8886
Description: "Force ANSI output",
89-
Default: Any{false},
87+
Default: false,
9088
Hidden: true,
9189
}
9290
NoAnsiOption = Option{
@@ -96,7 +94,7 @@ var (
9694
IsValueRequired: false,
9795
IsMultiple: false,
9896
Description: "Disable ANSI output",
99-
Default: Any{false},
97+
Default: false,
10098
Hidden: true,
10199
}
102100
NoOption = Option{
@@ -107,7 +105,7 @@ var (
107105
IsMultiple: false,
108106
Description: "Answer \"no\" to confirmation questions; " +
109107
"accept the default value for other questions; disable interaction",
110-
Default: Any{false},
108+
Default: false,
111109
Hidden: true,
112110
}
113111
QuietOption = Option{
@@ -117,7 +115,7 @@ var (
117115
IsValueRequired: false,
118116
IsMultiple: false,
119117
Description: "Do not output any message",
120-
Default: Any{false},
118+
Default: false,
121119
Hidden: true,
122120
}
123121
)

0 commit comments

Comments
 (0)