Skip to content

Commit c0d9de7

Browse files
help command is now part of mc admin config get/set
1 parent 9a9a6d8 commit c0d9de7

File tree

7 files changed

+120
-101
lines changed

7 files changed

+120
-101
lines changed

cmd/admin-config-del.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package cmd
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
22-
"os"
2321
"strings"
2422

2523
"github.com/fatih/color"
@@ -29,12 +27,19 @@ import (
2927
"github.com/minio/mc/pkg/probe"
3028
)
3129

30+
var adminConfigEnvFlags = []cli.Flag{
31+
cli.BoolFlag{
32+
Name: "env",
33+
Usage: "list all the env only help",
34+
},
35+
}
36+
3237
var adminConfigDelCmd = cli.Command{
3338
Name: "del",
3439
Usage: "delete a key from MinIO server/cluster.",
3540
Before: setGlobalsFromContext,
3641
Action: mainAdminConfigDel,
37-
Flags: globalFlags,
42+
Flags: append(adminConfigEnvFlags, globalFlags...),
3843
CustomHelpTemplate: `NAME:
3944
{{.HelpName}} - {{.Usage}}
4045
@@ -100,13 +105,22 @@ func mainAdminConfigDel(ctx *cli.Context) error {
100105
client, err := newAdminClient(aliasedURL)
101106
fatalIf(err, "Unable to initialize admin connection.")
102107

108+
if len(ctx.Args()) == 1 {
109+
// Call get config API
110+
hr, e := client.HelpConfigKV("", "", ctx.IsSet("env"))
111+
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
112+
113+
// Print
114+
printMsg(configHelpMessage{
115+
Value: hr,
116+
envOnly: ctx.IsSet("env"),
117+
})
118+
119+
return nil
120+
}
121+
103122
// Call del config API
104123
input := strings.Join(args.Tail(), " ")
105-
if len(input) == 0 {
106-
b, e := ioutil.ReadAll(os.Stdin)
107-
fatalIf(probe.NewError(e), "Cannot read from the os.Stdin")
108-
input = string(b)
109-
}
110124
fatalIf(probe.NewError(client.DelConfigKV(input)),
111125
"Cannot delete '%s' on the server", input)
112126

cmd/admin-config-get.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (u configGetMessage) JSON() string {
8080

8181
// checkAdminConfigGetSyntax - validate all the passed arguments
8282
func checkAdminConfigGetSyntax(ctx *cli.Context) {
83-
if !ctx.Args().Present() || len(ctx.Args()) > 2 {
83+
if !ctx.Args().Present() || len(ctx.Args()) < 1 {
8484
cli.ShowCommandHelpAndExit(ctx, "get", 1) // last argument is exit code
8585
}
8686
}
@@ -97,6 +97,20 @@ func mainAdminConfigGet(ctx *cli.Context) error {
9797
client, err := newAdminClient(aliasedURL)
9898
fatalIf(err, "Unable to initialize admin connection.")
9999

100+
if len(ctx.Args()) == 1 {
101+
// Call get config API
102+
hr, e := client.HelpConfigKV("", "", false)
103+
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
104+
105+
// Print
106+
printMsg(configHelpMessage{
107+
Value: hr,
108+
envOnly: false,
109+
})
110+
111+
return nil
112+
}
113+
100114
// Call get config API
101115
buf, e := client.GetConfigKV(strings.Join(args.Tail(), " "))
102116
fatalIf(probe.NewError(e), "Cannot get server '%s' config", args.Tail())

cmd/admin-config-help.go

Lines changed: 13 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,75 +17,41 @@
1717
package cmd
1818

1919
import (
20+
"encoding/json"
2021
"strings"
2122
"text/tabwriter"
2223
"text/template"
2324

2425
"github.com/fatih/color"
25-
"github.com/minio/cli"
26-
json "github.com/minio/mc/pkg/colorjson"
2726
"github.com/minio/mc/pkg/probe"
27+
"github.com/minio/minio/pkg/madmin"
2828
)
2929

30-
var helpFlags = []cli.Flag{
31-
cli.BoolFlag{
32-
Name: "env",
33-
Usage: "list all the env only help",
34-
},
35-
}
36-
37-
// Help template used by all sub-systems
38-
const Help = `{{colorBlueBold "Key"}}{{"\t"}}{{colorBlueBold "Description"}}
39-
{{colorYellowBold "----"}}{{"\t"}}{{colorYellowBold "----"}}
40-
{{range $key, $value := .}}{{colorCyanBold $key}}{{ "\t" }}{{$value}}
41-
{{end}}`
30+
// HelpTmpl template used by all sub-systems
31+
const HelpTmpl = `{{if ne .SubSys ""}}{{colorBlueBold "KEY:"}}
32+
{{if .MultipleTargets}}{{colorYellowBold .SubSys}}[:target]{{"\t"}}{{else}}{{colorYellowBold .SubSys}}{{"\t"}}{{end}}{{.Description}}
4233
43-
// HelpEnv template used by all sub-systems
44-
const HelpEnv = `{{colorBlueBold "KeyEnv"}}{{"\t"}}{{colorBlueBold "Description"}}
45-
{{colorYellowBold "----"}}{{"\t"}}{{colorYellowBold "----"}}
46-
{{range $key, $value := .}}{{colorCyanBold $key}}{{ "\t" }}{{$value}}
47-
{{end}}`
34+
{{colorBlueBold "ARGS:"}}{{range .KeysHelp}}
35+
{{if .Optional}}{{colorYellowBold .Key}}{{else}}{{colorRedBold .Key}}*{{end}}{{"\t"}}({{.Type}}){{"\t"}}{{.Description}}{{end}}{{else}}{{colorBlueBold "KEYS:"}}{{range .KeysHelp}}
36+
{{colorRedBold .Key}}*{{"\t"}}{{.Description}}{{end}}{{end}}`
4837

4938
var funcMap = template.FuncMap{
5039
"colorBlueBold": color.New(color.FgBlue, color.Bold).SprintfFunc(),
5140
"colorYellowBold": color.New(color.FgYellow, color.Bold).SprintfFunc(),
5241
"colorCyanBold": color.New(color.FgCyan, color.Bold).SprintFunc(),
42+
"colorRedBold": color.New(color.FgRed, color.Bold).SprintfFunc(),
5343
}
5444

5545
// HelpTemplate - captures config help template
56-
var HelpTemplate = template.Must(template.New("config-help").Funcs(funcMap).Parse(Help))
46+
var HelpTemplate = template.Must(template.New("config-help").Funcs(funcMap).Parse(HelpTmpl))
5747

5848
// HelpEnvTemplate - captures config help template
59-
var HelpEnvTemplate = template.Must(template.New("config-help-env").Funcs(funcMap).Parse(HelpEnv))
60-
61-
var adminConfigHelpCmd = cli.Command{
62-
Name: "help",
63-
Usage: "show help for each sub-system and keys",
64-
Before: setGlobalsFromContext,
65-
Action: mainAdminConfigHelp,
66-
Flags: append(append([]cli.Flag{}, globalFlags...), helpFlags...),
67-
CustomHelpTemplate: `NAME:
68-
{{.HelpName}} - {{.Usage}}
69-
70-
USAGE:
71-
{{.HelpName}} TARGET
72-
73-
FLAGS:
74-
{{range .VisibleFlags}}{{.}}
75-
{{end}}
76-
EXAMPLES:
77-
1. Return help for 'region' settings on MinIO server.
78-
{{.Prompt}} {{.HelpName}} play/ region
79-
80-
2. Return help for 'compression' settings, specifically 'extensions' key on MinIO server.
81-
{{.Prompt}} {{.HelpName}} myminio/ compression extensions
82-
`,
83-
}
49+
var HelpEnvTemplate = template.Must(template.New("config-help-env").Funcs(funcMap).Parse(HelpTmpl))
8450

8551
// configHelpMessage container to hold locks information.
8652
type configHelpMessage struct {
87-
Status string `json:"status"`
88-
Value map[string]string `json:"help"`
53+
Status string `json:"status"`
54+
Value madmin.Help `json:"help"`
8955
envOnly bool
9056
}
9157

@@ -114,35 +80,3 @@ func (u configHelpMessage) JSON() string {
11480

11581
return string(statusJSONBytes)
11682
}
117-
118-
// checkAdminConfigHelpSyntax - validate all the passed arguments
119-
func checkAdminConfigHelpSyntax(ctx *cli.Context) {
120-
if !ctx.Args().Present() || len(ctx.Args()) > 3 {
121-
cli.ShowCommandHelpAndExit(ctx, "help", 1) // last argument is exit code
122-
}
123-
}
124-
125-
func mainAdminConfigHelp(ctx *cli.Context) error {
126-
127-
checkAdminConfigHelpSyntax(ctx)
128-
129-
// Help the alias parameter from cli
130-
args := ctx.Args()
131-
aliasedURL := args.Get(0)
132-
133-
// Create a new MinIO Admin Client
134-
client, err := newAdminClient(aliasedURL)
135-
fatalIf(err, "Unable to initialize admin connection.")
136-
137-
// Call get config API
138-
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"))
139-
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
140-
141-
// Print
142-
printMsg(configHelpMessage{
143-
Value: hr,
144-
envOnly: ctx.IsSet("env"),
145-
})
146-
147-
return nil
148-
}

cmd/admin-config-set.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ package cmd
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
22-
"os"
2321
"strings"
2422

2523
"github.com/fatih/color"
2624
"github.com/minio/cli"
2725
json "github.com/minio/mc/pkg/colorjson"
2826
"github.com/minio/mc/pkg/console"
2927
"github.com/minio/mc/pkg/probe"
28+
"github.com/minio/minio/pkg/madmin"
3029
)
3130

3231
var adminConfigSetCmd = cli.Command{
3332
Name: "set",
3433
Usage: "set key to MinIO server/cluster.",
3534
Before: setGlobalsFromContext,
3635
Action: mainAdminConfigSet,
37-
Flags: globalFlags,
36+
Flags: append(adminConfigEnvFlags, globalFlags...),
3837
CustomHelpTemplate: `NAME:
3938
{{.HelpName}} - {{.Usage}}
4039
@@ -80,7 +79,7 @@ func (u configSetMessage) JSON() string {
8079

8180
// checkAdminConfigSetSyntax - validate all the passed arguments
8281
func checkAdminConfigSetSyntax(ctx *cli.Context) {
83-
if !ctx.Args().Present() {
82+
if !ctx.Args().Present() && len(ctx.Args()) < 1 {
8483
cli.ShowCommandHelpAndExit(ctx, "set", 1) // last argument is exit code
8584
}
8685
}
@@ -102,13 +101,24 @@ func mainAdminConfigSet(ctx *cli.Context) error {
102101
client, err := newAdminClient(aliasedURL)
103102
fatalIf(err, "Unable to initialize admin connection.")
104103

105-
// Call set config API
106104
input := strings.Join(args.Tail(), " ")
107-
if len(input) == 0 {
108-
b, e := ioutil.ReadAll(os.Stdin)
109-
fatalIf(probe.NewError(e), "Cannot read from the os.Stdin")
110-
input = string(b)
105+
106+
if !strings.Contains(input, madmin.KvSeparator) {
107+
// Call get config API
108+
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"))
109+
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
110+
111+
// Print
112+
printMsg(configHelpMessage{
113+
Value: hr,
114+
envOnly: ctx.IsSet("env"),
115+
})
116+
117+
return nil
118+
111119
}
120+
121+
// Call set config API
112122
fatalIf(probe.NewError(client.SetConfigKV(input)),
113123
"Cannot set '%s' to server", input)
114124

cmd/admin-config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var adminConfigCmd = cli.Command{
2828
adminConfigSetCmd,
2929
adminConfigGetCmd,
3030
adminConfigDelCmd,
31-
adminConfigHelpCmd,
3231
adminConfigHistoryCmd,
3332
},
3433
HideHelpCommand: true,

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ module github.com/minio/mc
33
go 1.13
44

55
require (
6+
contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect
7+
github.com/DataDog/zstd v1.4.4 // indirect
68
github.com/cheggaaa/pb v1.0.28
79
github.com/dgrijalva/jwt-go v3.2.0+incompatible
810
github.com/dustin/go-humanize v1.0.0
911
github.com/fatih/color v1.7.0
1012
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
1113
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
12-
github.com/grpc-ecosystem/grpc-gateway v1.9.4 // indirect
14+
github.com/hashicorp/go-retryablehttp v0.6.3 // indirect
1315
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
1416
github.com/mattn/go-colorable v0.1.1
1517
github.com/mattn/go-isatty v0.0.7
1618
github.com/mattn/go-runewidth v0.0.5 // indirect
1719
github.com/minio/cli v1.22.0
18-
github.com/minio/minio v0.0.0-20191114013805-26a866a20245
20+
github.com/minio/minio v0.0.0-20191119214813-7cdb67680e72
1921
github.com/minio/minio-go/v6 v6.0.41
2022
github.com/minio/sha256-simd v0.1.1
2123
github.com/mitchellh/go-homedir v1.1.0
@@ -27,7 +29,6 @@ require (
2729
go.uber.org/zap v1.11.0 // indirect
2830
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
2931
golang.org/x/text v0.3.2
30-
google.golang.org/grpc v1.22.0 // indirect
3132
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
3233
gopkg.in/h2non/filetype.v1 v1.0.5
3334
gopkg.in/yaml.v2 v2.2.2

0 commit comments

Comments
 (0)