Skip to content

Commit

Permalink
Various Cosmetic Updates (#204)
Browse files Browse the repository at this point in the history
Various cosmetic updates
  • Loading branch information
yuce authored Apr 6, 2023
1 parent c45605a commit b54058a
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 32 deletions.
19 changes: 18 additions & 1 deletion base/commands/config/config_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ import (
type AddCmd struct{}

func (cm AddCmd) Init(cc plug.InitContext) error {
cc.SetCommandUsage("add TARGET")
cc.SetCommandUsage("add [configuration-name]")
short := "Adds a configuration"
long := `Adds a configuration with the given name/path and KEY=VALUE pairs
Overrides the previous configuration if it exists.
The following keys are supported:
* cluster.name STRING
* cluster.address STRING
* cluster.user STRING
* cluster.password STRING
* cluster.discovery-token STRING
* ssl.enabled BOOLEAN (true / false)
* ssl.server STRING
* ssl.skip-verify BOOLEAN (true / false)
* ssl.ca-path STRING
* ssl.key-path STRING
* ssl.key-password STRING
* log.path STRING
* log.level ENUM (error / warn / info / debug)
`
cc.SetCommandHelp(long, short)
cc.SetPositionalArgCount(1, math.MaxInt)
Expand Down
24 changes: 21 additions & 3 deletions base/commands/config/config_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@ import (
type ImportCmd struct{}

func (cm ImportCmd) Init(cc plug.InitContext) error {
cc.SetCommandUsage("import TARGET SOURCE")
help := "Imports configuration from an arbitrary source"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("import [configuration-name] [source]")
short := "Imports configuration from an arbitrary source"
long := `Imports configuration from an arbitrary source
Currently importing only Viridian connection configuration is supported.
1. On Viridian console, visit:
Dashboard -> Connect Client -> Quick connection guide -> Go
2. Copy the text in box 1 and pass it as the second parameter.
Make sure the text is quoted before running:
clc config import my-config "curl https://api.viridian.hazelcast.com ... default.zip"
Alternatively, you can use an already downloaded Go client sample:
clc config import my-config /home/me/Downloads/hazelcast-cloud-go-sample....zip
`
cc.SetCommandHelp(long, short)
cc.SetPositionalArgCount(2, 2)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion base/commands/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (hc HomeCommand) Init(cc plug.InitContext) error {
help := "Print the CLC home directory, optionally by joining the given sub-paths"
cc.SetCommandHelp(help, help)
cc.SetPositionalArgCount(0, math.MaxInt)
cc.SetCommandUsage("home [SUBPATH ...] [flags]")
cc.SetCommandUsage("home [subpath ...] [flags]")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (mc *MapCommand) Init(cc plug.InitContext) error {
cc.AddStringFlag(clc.PropertySchemaDir, "", paths.Schemas(), false, "set the schema directory")
}
cc.SetTopLevel(true)
cc.SetCommandUsage("map COMMAND [flags]")
cc.SetCommandUsage("map [command] [flags]")
help := "Map operations"
cc.SetCommandHelp(help, help)
return nil
Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map_clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type MapClearCommand struct{}
func (mc *MapClearCommand) Init(cc plug.InitContext) error {
help := "Delete all entries of a Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("clear [-n MAP] [flags]")
cc.SetCommandUsage("clear [-n map-name] [flags]")
return nil
}

Expand Down
10 changes: 8 additions & 2 deletions base/commands/map/map_entry_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type MapEntrySetCommand struct{}
func (mc *MapEntrySetCommand) Init(cc plug.InitContext) error {
help := "Get all entries of a Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("entry-set [-n MAP] [flags]")
cc.SetCommandUsage("entry-set [-n map-name] [flags]")
cc.SetPositionalArgCount(0, 0)
return nil
}
Expand All @@ -44,7 +44,13 @@ func (mc *MapEntrySetCommand) Exec(ctx context.Context, ec plug.ExecContext) err
stop()
pairs := codec.DecodeMapEntrySetResponse(rv.(*hazelcast.ClientMessage))
rows := output.DecodePairs(ci, pairs, showType)
return ec.AddOutputRows(ctx, rows...)
if len(rows) > 0 {
return ec.AddOutputRows(ctx, rows...)
}
if !ec.Props().GetBool(clc.PropertyQuite) {
I2(fmt.Fprintln(ec.Stdout(), "No entries found"))
}
return nil
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (mc *MapGetCommand) Init(cc plug.InitContext) error {
addKeyTypeFlag(cc)
help := "Get a value from the given Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("get [-n MAP] KEY [flags]")
cc.SetCommandUsage("get [-n map-name] [key] [flags]")
cc.SetPositionalArgCount(1, 1)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (mc *MapRemoveCommand) Init(cc plug.InitContext) error {
addKeyTypeFlag(cc)
help := "Remove a value from the given Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("remove [-n MAP] KEY [flags]")
cc.SetCommandUsage("remove [-n map-name] [key] [flags]")
cc.SetPositionalArgCount(1, 1)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (mc *MapSetCommand) Init(cc plug.InitContext) error {
cc.SetPositionalArgCount(2, 2)
help := "Set a value in the given Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("set [-n MAP] KEY VALUE [flags]")
cc.SetCommandUsage("set [-n MAP] [key] [value] [flags]")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion base/commands/map/map_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MapSizeCommand struct{}
func (mc *MapSizeCommand) Init(cc plug.InitContext) error {
help := "Return the size of the given Map"
cc.SetCommandHelp(help, help)
cc.SetCommandUsage("size [-n MAP]")
cc.SetCommandUsage("size [-n map-name]")
cc.SetPositionalArgCount(0, 0)
return nil
}
Expand Down
15 changes: 9 additions & 6 deletions base/commands/object/object_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ var objTypes = []string{
Cache,
EventJournal,
Ringbuffer,
FencedLock,
ISemaphore,
IAtomicLong,
IAtomicReference,
ICountdownLatch,
CardinalityEstimator,
}

Expand All @@ -70,7 +65,9 @@ func (cm ObjectListCommand) Init(cc plug.InitContext) error {
long := fmt.Sprintf(`List distributed objects, optionally filter by type.
The object-type filter may be one of:
%s
CP objects such as AtomicLong cannot be listed.
`, objectFilterTypes())
cc.SetCommandHelp(long, "List distributed objects")
cc.AddBoolFlag(flagShowHidden, "", false, false, "show hidden and system objects")
Expand Down Expand Up @@ -108,7 +105,13 @@ func (cm ObjectListCommand) Exec(ctx context.Context, ec plug.ExecContext) error
valueCol,
})
}
return ec.AddOutputRows(ctx, rows...)
if len(rows) > 0 {
return ec.AddOutputRows(ctx, rows...)
}
if !ec.Props().GetBool(clc.PropertyQuite) {
I2(fmt.Fprintln(ec.Stdout(), "No objects found"))
}
return nil
}

func objectFilterTypes() string {
Expand Down
1 change: 1 addition & 0 deletions base/commands/sql/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func UpdateOutput(ctx context.Context, ec plug.ExecContext, res sql.Result, verb
errCh <- err
break
}
// TODO: move the following 2 lines out of the loop --YT
cols := row.Metadata().Columns()
orow := make(output.Row, len(cols))
for i, col := range cols {
Expand Down
2 changes: 1 addition & 1 deletion base/commands/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (cm *SQLCommand) Init(cc plug.InitContext) error {
if cc.Interactive() {
return errors.ErrNotAvailable
}
cc.SetCommandUsage("sql [QUERY] [flags]")
cc.SetCommandUsage("sql [query] [flags]")
cc.SetPositionalArgCount(1, 1)
cc.AddCommandGroup("sql", "SQL")
cc.SetCommandGroup("sql")
Expand Down
4 changes: 2 additions & 2 deletions clc/cmd/exec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ func (ec *ExecContext) Wrap(f func() error) error {
}
var msg string
if verbose || ec.Interactive() {
msg = fmt.Sprintf("\nOK (%d ms)", took.Milliseconds())
msg = fmt.Sprintf("OK (%d ms)", took.Milliseconds())
} else {
msg = "\nOK"
msg = "OK"
}
I2(fmt.Fprintln(ec.stdout, msg))
return nil
Expand Down
3 changes: 0 additions & 3 deletions clc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ func MakeHzConfig(props plug.ReadOnlyProperties, lg log.Logger) (hazelcast.Confi
var viridianEnabled bool
if vt := props.GetString(clc.PropertyClusterDiscoveryToken); vt != "" {
lg.Debugf("Viridan token: XXX")
if err := os.Setenv(clc.EnvHzCloudCoordinatorBaseURL, clc.ViridianCoordinatorURL); err != nil {
return cfg, fmt.Errorf("setting coordinator URL")
}
cfg.Cluster.Cloud.Enabled = true
cfg.Cluster.Cloud.Token = vt
viridianEnabled = true
Expand Down
25 changes: 21 additions & 4 deletions clc/config/wizard/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,27 @@ func (m textModel) View() string {
return ""
}
var b strings.Builder
b.WriteString(
"There is no configuration detected. You can register a new configuration to connect Hazelcast cluster.\n" +
"You can connect to Viridian cluster using curl request from `Dashboard -> Connect Client -> Quick connection guide -> Go` tab.\n" +
"Paste the link to source field below and it will download the config and TLS files.\n\n")
b.WriteString(`There is no configuration detected.
This screen helps you create a new connection configuration.
Note that this screen supports only Viridian clusters.
For other clusters use the following command:
clc config add --help
1. Enter the desired name in the "Configuration Name" field.
2. On Viridian console, visit:
Dashboard -> Connect Client -> Quick connection guide -> Go
3. Copy the text in box 1 and paste it in the "Source" field.
4. Navigate to the [Submit] button and press enter.
Alternatively, you can use the following command:
clc config import --help
`)
for i := range m.inputs {
b.WriteString(m.inputs[i].View())
if i < len(m.inputs)-1 {
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/alecthomas/chroma v0.10.0
github.com/gohxs/readline v0.0.0-20171011095936-a780388e6e7c
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hazelcast/hazelcast-go-client v1.4.0
github.com/hazelcast/hazelcast-go-client v1.4.1-0.20230404141417-cffc4cae7feb
github.com/mattn/go-runewidth v0.0.14
github.com/nathan-fiscaletti/consolesize-go v0.0.0-20210105204122-a87d9f614b9d
github.com/spf13/cobra v1.6.0
Expand Down Expand Up @@ -67,5 +67,3 @@ require (
github.com/nyaosorg/go-readline-ny v0.8.3
gopkg.in/yaml.v2 v2.4.0
)

replace github.com/hazelcast/hazelcast-go-client v1.4.0 => github.com/yuce/hazelcast-go-client v1.1.2-0.20230404141417-cffc4cae7feb

0 comments on commit b54058a

Please sign in to comment.