Skip to content

Commit

Permalink
Simplify examples (#78)
Browse files Browse the repository at this point in the history
* simplify examples

* add available mode for use command

* minor fixes

* minor fixes
  • Loading branch information
utku-caglayan authored Jun 8, 2022
1 parent 972df93 commit af57a78
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 74 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ hzc --address <ADDRESSES> --cluster-name <YOUR_CLUSTER_NAME>
### Requirements
* Go 1.15 or better
* Make
### Download the repository using Git
```
Expand All @@ -272,5 +273,5 @@ git clone https://github.com/hazelcast/hazelcast-commandline-client.git
```
cd hazelcast-commandline-client
go build -o hzc github.com/hazelcast/hazelcast-commandline-client
make
```
2 changes: 1 addition & 1 deletion internal/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ConvertString(value, valueType string) (interface{}, error) {
case TypeNameFloat64:
cv, err = strconv.ParseFloat(value, 64)
default:
err = fmt.Errorf("unknown type, provide one of %v", strings.Join(SupportedTypeNames, ","))
err = fmt.Errorf("unknown type, provide one of %s", strings.Join(SupportedTypeNames, ","))
}
if errors.Is(err, strconv.ErrSyntax) {
err = fmt.Errorf(`can not convert "%s" to %s, unknown syntax`, value, valueType)
Expand Down
6 changes: 0 additions & 6 deletions types/mapcmd/get-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ import (
)

const MapGetAllExample = ` # Get matched entries from the map with default delimiter. Default delimiter is the tab character.
hzc get-all -n mapname -k k1 -k k2
# Get matched entries from the map with custom delimiter.
hzc get-all -n mapname -k k1 -k k2 --delim ":"
# Get matched entries with denoted type from the map with custom delimiter.
hzc get-all -n mapname -k 12 -k 25 --key-type int16 --delim ":"`

func NewGetAll(config *hazelcast.Config) *cobra.Command {
Expand Down
4 changes: 1 addition & 3 deletions types/mapcmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
)

const MapGetExample = ` # Get value of the given key from the map.
hzc map get -n mapname -k k1
hzc map get --key hello --name myMap
hzc map get --key-type int16 --key 2012 --name yearbook`
hzc map get --key-type int16 --key 2012 --name myMap # default key-type is string`

func NewGet(config *hazelcast.Config) *cobra.Command {
var mapName, mapKey, mapKeyType string
Expand Down
35 changes: 5 additions & 30 deletions types/mapcmd/put-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,12 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/internal"
)

const MapPutAllExample = ` # Put key, value pairs to map.
hzc map put-all -n mapname -k k1 -v v1 -k k2 -v v2
# Put key, value pairs to map in another order.
hzc map put-all -n mapname -k k1 -k k2 -v v1 -v v2
# Put key, value pairs to map with value types as JSON (default type string)
hzc map put-all -n mapname -k k1 -f valueFile.json -k k2 -v '{"field":"tmp"}' -t json
# Put key, value pairs while specifying types of both keys and values
const MapPutAllExample = ` # Put key, value pairs while specifying types of both keys and values
# Keys and values are matched with the given order
hzc map put-all -n mapname --key-type int16 -k 1 -k 2 --value-type json -f valueFile.json -v '{"field":"tmp"}'
# Put all key, value pairs to map from the entry json file .
# Put all key, value pairs to map from the entry json file. Null values are ignored.
hzc map put-all -n mapname --json-entry entries.json
# Example json entry file
{
"key1": "value1",
"key2": {
"innerData": "data",
"anotherInnerData": 5.0
},
"key3": true,
"key4": [1, 2, 3, 4, 5]
}
- Entries with "null" values are being ignored.
# Coupling rule of keys and values given in different order
- Keys and values are coupled according to the order they are provided. That means the first given key will be matched with the first given
value from left to right. Therefore, keys and values (given through file or directly from the command line) must be equal in number.
- Given key type or value type applied to all entries. For the missing type, string is accepted as a type.
`

func NewPutAll(config *hazelcast.Config) *cobra.Command {
Expand Down Expand Up @@ -211,8 +186,8 @@ func NewPutAll(config *hazelcast.Config) *cobra.Command {
decorateCommandWithMapKeyTypeFlags(cmd, &mapKeyType, false)
decorateCommandWithMapValueArrayFlags(cmd, &mapValues, false, "value(s) of the map")
decorateCommandWithMapValueFileArrayFlags(cmd, &mapValueFiles, false,
"`path to the file that contains the value. Use \"-\" (dash) to read from stdin`")
`path to the file that contains the value. Use "-" (dash) to read from stdin`)
decorateCommandWithMapValueTypeFlags(cmd, &mapValueType, false)
decorateCommandWithJSONEntryFlag(cmd, &jsonEntryPath, false, "`path to json file that contains entries`")
decorateCommandWithJSONEntryFlag(cmd, &jsonEntryPath, false, `path to json file that contains entries`)
return cmd
}
31 changes: 2 additions & 29 deletions types/mapcmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,8 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/internal"
)

const MapPutExample = ` # Put key, value pair to map.
hzc put -n mapname -k k1 -v v1
# Put key, value pair to map but type of the value is accepted as json data.
hzc map put -n mapname -k k2 -v v2 -t json
# Put key, value pair to map but the value is given through external file.
hzc map put -n mapname -k k3 -f v3.txt
# Put key, value pair to map but the value is given through external json file.
hzc map put -n mapname -k k4 -f v4.json -t json
# Put key, value pair to map with given ttl value
hzc map put -n mapname -k k5 -v v5 --ttl 3ms
# Put key, value pair to map with given ttl and maxidle values
hzc map put -n mapname -k k1 -v v1 --ttl 3ms --max-idle 4ms
# Put custom type key and value to map
map put --key-type string --key hello --value-type float32 --value 19.94 --name myMap
# TTL and Maxidle:
ttl and maxidle values cannot be less than a second when it is converted to second from any time unit. Supported units are;
- Nanosecond (ns)
- Microsecond (μs)
- Millisecond (ms)
- Second (s)
- Minute (m)
- Hour (h)`
const MapPutExample = ` # Put key, value pair to map. The unit for ttl/max-idle is one of (ns,us,ms,s,m,h)
map put --key-type string --key hello --value-type float32 --value 19.94 --name myMap --ttl 1300ms --max-idle 1400ms`

func NewPut(config *hazelcast.Config) *cobra.Command {
var (
Expand Down
4 changes: 2 additions & 2 deletions types/mapcmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewRemove(config *hazelcast.Config) *cobra.Command {
)
cmd := &cobra.Command{
Use: "remove [--name mapname | --key keyname]",
Short: "Remove key(s)",
Example: ` # Remove key from the map if it exists.
Short: "Remove key",
Example: ` # Remove key from the map
hzc map remove -n mapname -k k1`,
RunE: func(cmd *cobra.Command, args []string) error {
key, err := internal.ConvertString(mapKey, mapKeyType)
Expand Down
4 changes: 2 additions & 2 deletions types/mapcmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
)

const MapUseExample = ` hzc map use m1 # sets the default map name to m1 unless set explicitly
hzc map get --key k1 # --name m1\" is inferred
hzc map get --key k1 # "--name m1" is inferred
hzc map use --reset # resets the behaviour`

func NewUse() *cobra.Command {
cmd := &cobra.Command{
Use: `use [map-name | --reset]`,
Short: "sets default map name",
Short: "sets the default map name (interactive-mode only)",
Example: MapUseExample,
RunE: func(cmd *cobra.Command, args []string) error {
persister := internal.PersistedNamesFromContext(cmd.Context())
Expand Down

0 comments on commit af57a78

Please sign in to comment.