Skip to content

Commit

Permalink
help command is now part of mc admin config get/set
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Nov 19, 2019
1 parent 9aebf1e commit 099226d
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 97 deletions.
21 changes: 14 additions & 7 deletions cmd/admin-config-del.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -100,13 +98,22 @@ func mainAdminConfigDel(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

if len(ctx.Args()) == 1 {
// Call get config API
hr, e := client.HelpConfigKV("", "", ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
printMsg(configHelpMessage{
Value: hr,
envOnly: ctx.IsSet("env"),
})

return nil
}

// Call del config API
input := strings.Join(args.Tail(), " ")
if len(input) == 0 {
b, e := ioutil.ReadAll(os.Stdin)
fatalIf(probe.NewError(e), "Cannot read from the os.Stdin")
input = string(b)
}
fatalIf(probe.NewError(client.DelConfigKV(input)),
"Cannot delete '%s' on the server", input)

Expand Down
25 changes: 23 additions & 2 deletions cmd/admin-config-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ import (
"github.com/minio/minio/pkg/madmin"
)

var adminConfigGetFlags = []cli.Flag{
cli.BoolFlag{
Name: "env",
Usage: "list all the env only help",
},
}

var adminConfigGetCmd = cli.Command{
Name: "get",
Usage: "get config of a MinIO server/cluster",
Before: setGlobalsFromContext,
Action: mainAdminConfigGet,
Flags: globalFlags,
Flags: append(adminConfigGetFlags, globalFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down Expand Up @@ -80,7 +87,7 @@ func (u configGetMessage) JSON() string {

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

if len(ctx.Args()) == 1 {
// Call get config API
hr, e := client.HelpConfigKV("", "", ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
printMsg(configHelpMessage{
Value: hr,
envOnly: ctx.IsSet("env"),
})

return nil
}

// Call get config API
buf, e := client.GetConfigKV(strings.Join(args.Tail(), " "))
fatalIf(probe.NewError(e), "Cannot get server '%s' config", args.Tail())
Expand Down
93 changes: 14 additions & 79 deletions cmd/admin-config-help.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,42 @@
package cmd

import (
"encoding/json"
"strings"
"text/tabwriter"
"text/template"

"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/mc/pkg/colorjson"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)

var helpFlags = []cli.Flag{
cli.BoolFlag{
Name: "env",
Usage: "list all the env only help",
},
}

// Help template used by all sub-systems
const Help = `{{colorBlueBold "Key"}}{{"\t"}}{{colorBlueBold "Description"}}
{{colorYellowBold "----"}}{{"\t"}}{{colorYellowBold "----"}}
{{range $key, $value := .}}{{colorCyanBold $key}}{{ "\t" }}{{$value}}
{{end}}`
// HelpTmpl template used by all sub-systems
const HelpTmpl = `{{if ne .SubSys ""}}{{colorBlueBold "KEY:"}}
{{if .MultipleTargets}}{{colorYellowBold .SubSys}}[:target]{{"\t"}}{{else}}
{{colorYellowBold .SubSys}}{{"\t"}}{{end}}{{.Description}}
// HelpEnv template used by all sub-systems
const HelpEnv = `{{colorBlueBold "KeyEnv"}}{{"\t"}}{{colorBlueBold "Description"}}
{{colorYellowBold "----"}}{{"\t"}}{{colorYellowBold "----"}}
{{range $key, $value := .}}{{colorCyanBold $key}}{{ "\t" }}{{$value}}
{{end}}`
{{colorBlueBold "ARGS:"}}{{range .KeysHelp}}
{{if .Optional}}{{colorYellowBold .Key}}{{else}}{{colorRedBold .Key}}*{{end}}{{"\t"}}({{.Type}}){{"\t"}}{{.Description}}{{end}}{{else}}{{colorBlueBold "KEYS:"}}{{range .KeysHelp}}
{{colorRedBold .Key}}*{{"\t"}}{{.Description}}{{end}}{{end}}`

var funcMap = template.FuncMap{
"colorBlueBold": color.New(color.FgBlue, color.Bold).SprintfFunc(),
"colorYellowBold": color.New(color.FgYellow, color.Bold).SprintfFunc(),
"colorCyanBold": color.New(color.FgCyan, color.Bold).SprintFunc(),
"colorRedBold": color.New(color.FgRed, color.Bold).SprintfFunc(),
}

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

// HelpEnvTemplate - captures config help template
var HelpEnvTemplate = template.Must(template.New("config-help-env").Funcs(funcMap).Parse(HelpEnv))

var adminConfigHelpCmd = cli.Command{
Name: "help",
Usage: "show help for each sub-system and keys",
Before: setGlobalsFromContext,
Action: mainAdminConfigHelp,
Flags: append(append([]cli.Flag{}, globalFlags...), helpFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Return help for 'region' settings on MinIO server.
{{.Prompt}} {{.HelpName}} play/ region
2. Return help for 'compression' settings, specifically 'extensions' key on MinIO server.
{{.Prompt}} {{.HelpName}} myminio/ compression extensions
`,
}
var HelpEnvTemplate = template.Must(template.New("config-help-env").Funcs(funcMap).Parse(HelpTmpl))

// configHelpMessage container to hold locks information.
type configHelpMessage struct {
Status string `json:"status"`
Value map[string]string `json:"help"`
Status string `json:"status"`
Value madmin.Help `json:"help"`
envOnly bool
}

Expand Down Expand Up @@ -114,35 +81,3 @@ func (u configHelpMessage) JSON() string {

return string(statusJSONBytes)
}

// checkAdminConfigHelpSyntax - validate all the passed arguments
func checkAdminConfigHelpSyntax(ctx *cli.Context) {
if !ctx.Args().Present() || len(ctx.Args()) > 3 {
cli.ShowCommandHelpAndExit(ctx, "help", 1) // last argument is exit code
}
}

func mainAdminConfigHelp(ctx *cli.Context) error {

checkAdminConfigHelpSyntax(ctx)

// Help the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)

// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

// Call get config API
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
printMsg(configHelpMessage{
Value: hr,
envOnly: ctx.IsSet("env"),
})

return nil
}
26 changes: 18 additions & 8 deletions cmd/admin-config-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/mc/pkg/colorjson"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)

var adminConfigSetCmd = cli.Command{
Expand Down Expand Up @@ -80,7 +79,7 @@ func (u configSetMessage) JSON() string {

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

// Call set config API
input := strings.Join(args.Tail(), " ")
if len(input) == 0 {
b, e := ioutil.ReadAll(os.Stdin)
fatalIf(probe.NewError(e), "Cannot read from the os.Stdin")
input = string(b)

if !strings.Contains(input, madmin.KvSeparator) {
// Call get config API
hr, e := client.HelpConfigKV(args.Get(1), args.Get(2), ctx.IsSet("env"))
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")

// Print
printMsg(configHelpMessage{
Value: hr,
envOnly: ctx.IsSet("env"),
})

return nil

}

// Call set config API
fatalIf(probe.NewError(client.SetConfigKV(input)),
"Cannot set '%s' to server", input)

Expand Down
1 change: 0 additions & 1 deletion cmd/admin-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var adminConfigCmd = cli.Command{
adminConfigSetCmd,
adminConfigGetCmd,
adminConfigDelCmd,
adminConfigHelpCmd,
adminConfigHistoryCmd,
},
HideHelpCommand: true,
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ require (
)

replace github.com/gorilla/rpc v1.2.0+incompatible => github.com/gorilla/rpc v1.2.0

replace github.com/minio/minio => ../minio
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,22 @@ github.com/nats-io/go-nats v1.7.2/go.mod h1:+t7RHT5ApZebkrQdnn6AhQJmhJJiKAvJUio1
github.com/nats-io/go-nats-streaming v0.0.0-20161216191029-077898146bfb/go.mod h1:gfq4R3c9sKAINOpelo0gn/b9QDMBZnmrttcsNF+lqyo=
github.com/nats-io/go-nats-streaming v0.4.2/go.mod h1:gfq4R3c9sKAINOpelo0gn/b9QDMBZnmrttcsNF+lqyo=
github.com/nats-io/go-nats-streaming v0.4.4/go.mod h1:gfq4R3c9sKAINOpelo0gn/b9QDMBZnmrttcsNF+lqyo=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
github.com/nats-io/nats v0.0.0-20160916181735-70b70be17b77/go.mod h1:PpmYZwlgTfBI56QypJLfIMOfLnMRuVs+VL6r8mQ2SoQ=
github.com/nats-io/nats v1.7.2/go.mod h1:PpmYZwlgTfBI56QypJLfIMOfLnMRuVs+VL6r8mQ2SoQ=
github.com/nats-io/nats-server v1.4.1/go.mod h1:c8f/fHd2B6Hgms3LtCaI7y6pC4WD1f4SUxcCud5vhBc=
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
github.com/nats-io/nats-streaming-server v0.12.2/go.mod h1:RyqtDJZvMZO66YmyjIYdIvS69zu/wDAkyNWa8PIUa5c=
github.com/nats-io/nats-streaming-server v0.14.1/go.mod h1:RyqtDJZvMZO66YmyjIYdIvS69zu/wDAkyNWa8PIUa5c=
github.com/nats-io/nats-streaming-server v0.14.2/go.mod h1:RyqtDJZvMZO66YmyjIYdIvS69zu/wDAkyNWa8PIUa5c=
github.com/nats-io/nats.go v1.8.0 h1:PXePcr71qzI9MMvQFfV0OBuNItkRQyyZowPfXzvdmVI=
github.com/nats-io/nats.go v1.8.0/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
github.com/nats-io/nkeys v0.0.2 h1:+qM7QpgXnvDDixitZtQUBDY9w/s9mu1ghS+JIbsrx6M=
github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4=
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.0/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
Expand Down Expand Up @@ -706,6 +712,7 @@ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
Expand Down Expand Up @@ -780,6 +787,7 @@ golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down

0 comments on commit 099226d

Please sign in to comment.