mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00
MF-1551 - Fix Cobra usage commands and clean unnecessary struct types (#1558)
* MF-1551 - Fix Cobra usage commands and clean unnecessary struct types Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use linux syntax for cmd usage description Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix cmd.Use Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
655ac838be
commit
09cbc3f14b
@ -11,13 +11,13 @@ import (
|
||||
)
|
||||
|
||||
var cmdBootstrap = []cobra.Command{
|
||||
cobra.Command{
|
||||
Use: "add",
|
||||
Short: "add <JSON_config> <user_auth_token>",
|
||||
Long: `Adds new Thing Bootstrap Config to the user identified by the provided key`,
|
||||
{
|
||||
Use: "create <JSON_config> <user_auth_token>",
|
||||
Short: "Create config",
|
||||
Long: `Create new Thing Bootstrap Config to the user identified by the provided key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,13 +36,13 @@ var cmdBootstrap = []cobra.Command{
|
||||
logCreated(id)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "view",
|
||||
Short: "view <thing_id> <user_auth_token>",
|
||||
Long: `Returns Thing Config with given ID belonging to the user identified by the given key`,
|
||||
{
|
||||
Use: "get <thing_id> <user_auth_token>",
|
||||
Short: "Get config",
|
||||
Long: `Get Thing Config with given ID belonging to the user identified by the given key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -55,13 +55,13 @@ var cmdBootstrap = []cobra.Command{
|
||||
logJSON(c)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "update",
|
||||
Short: "update <JSON_config> <user_auth_token>",
|
||||
{
|
||||
Use: "update <JSON_config> <user_auth_token>",
|
||||
Short: "Update config",
|
||||
Long: `Updates editable fields of the provided Config`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -79,13 +79,13 @@ var cmdBootstrap = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "remove",
|
||||
Short: "remove <thing_id> <user_auth_token>",
|
||||
{
|
||||
Use: "remove <thing_id> <user_auth_token>",
|
||||
Short: "Remove config",
|
||||
Long: `Removes Config with specified key that belongs to the user identified by the given key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -97,13 +97,13 @@ var cmdBootstrap = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "bootstrap",
|
||||
Short: "bootstrap <external_id> <external_key>",
|
||||
{
|
||||
Use: "bootstrap <external_id> <external_key>",
|
||||
Short: "Bootstrap config",
|
||||
Long: `Returns Config to the Thing with provided external ID using external key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -121,12 +121,9 @@ var cmdBootstrap = []cobra.Command{
|
||||
// NewBootstrapCmd returns bootstrap command.
|
||||
func NewBootstrapCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "bootstrap",
|
||||
Use: "bootstrap [create | get | update | remove | bootstrap]",
|
||||
Short: "Bootstrap management",
|
||||
Long: `Bootstrap management: create, get, update or delete Bootstrap config`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("bootstrap [add | view | update | remove | bootstrap]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdBootstrap {
|
||||
|
11
cli/certs.go
11
cli/certs.go
@ -13,12 +13,12 @@ func NewCertsCmd() *cobra.Command {
|
||||
var ttl uint32
|
||||
|
||||
issueCmd := cobra.Command{
|
||||
Use: "issue",
|
||||
Short: "issue <thing_id> <user_auth_token> [--keysize=2048] [--keytype=rsa] [--ttl=8760]",
|
||||
Use: "issue <thing_id> <user_auth_token> [--keysize=2048] [--keytype=rsa] [--ttl=8760]",
|
||||
Short: "Issue certificate",
|
||||
Long: `Issues new certificate for a thing`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -39,12 +39,9 @@ func NewCertsCmd() *cobra.Command {
|
||||
issueCmd.Flags().Uint32Var(&ttl, "ttl", 8760, "certificate time to live in hours")
|
||||
|
||||
cmd := cobra.Command{
|
||||
Use: "certs",
|
||||
Use: "certs [issue | get]",
|
||||
Short: "Certificates management",
|
||||
Long: `Certificates management: create certificates for things"`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("certs [issue]")
|
||||
},
|
||||
}
|
||||
|
||||
cmdCerts := []cobra.Command{
|
||||
|
@ -11,13 +11,13 @@ import (
|
||||
)
|
||||
|
||||
var cmdChannels = []cobra.Command{
|
||||
cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create <JSON_channel> <user_auth_token>",
|
||||
{
|
||||
Use: "create <JSON_channel> <user_auth_token>",
|
||||
Short: "Create channel",
|
||||
Long: `Creates new channel and generates it's UUID`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,13 +36,13 @@ var cmdChannels = []cobra.Command{
|
||||
logCreated(id)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get [all | <channel_id>] <user_auth_token>",
|
||||
{
|
||||
Use: "get [all | <channel_id>] <user_auth_token>",
|
||||
Short: "Get channel",
|
||||
Long: `Gets list of all channels or gets channel by id`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -66,13 +66,13 @@ var cmdChannels = []cobra.Command{
|
||||
logJSON(c)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "update",
|
||||
Short: "update <JSON_string> <user_auth_token>",
|
||||
{
|
||||
Use: "updatev <JSON_string> <user_auth_token>",
|
||||
Short: "Update channel",
|
||||
Long: `Updates channel record`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -90,13 +90,13 @@ var cmdChannels = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "delete <channel_id> <user_auth_token>",
|
||||
{
|
||||
Use: "delete <channel_id> <user_auth_token>",
|
||||
Short: "Delete channel",
|
||||
Long: `Delete channel by ID`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -108,13 +108,13 @@ var cmdChannels = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "connections",
|
||||
Short: "connections <channel_id> <user_auth_token>",
|
||||
{
|
||||
Use: "connections <channel_id> <user_auth_token>",
|
||||
Short: "Connections list",
|
||||
Long: `List of Things connected to a Channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -127,13 +127,13 @@ var cmdChannels = []cobra.Command{
|
||||
logJSON(cl)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "not-connected",
|
||||
Short: "not-connected <channel_id> <user_auth_token>",
|
||||
{
|
||||
Use: "not-connected <channel_id> <user_auth_token>",
|
||||
Short: "Not-connected list",
|
||||
Long: `List of Things not connected to a Channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -151,12 +151,9 @@ var cmdChannels = []cobra.Command{
|
||||
// NewChannelsCmd returns channels command.
|
||||
func NewChannelsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "channels",
|
||||
Use: "channels [create | get | update | delete | connections | not-connected]",
|
||||
Short: "Channels management",
|
||||
Long: `Channels management: create, get, update or delete Channel and get list of Things connected or not connected to a Channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("channels [create | get | update | delete | connections | not-connected]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdChannels {
|
||||
|
@ -11,11 +11,10 @@ import (
|
||||
)
|
||||
|
||||
var cmdGroups = []cobra.Command{
|
||||
cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create <JSON_group> <user_auth_token>",
|
||||
Long: `Creates new group
|
||||
JSON_group:
|
||||
{
|
||||
Use: "create <JSON_group> <user_auth_token>",
|
||||
Short: "Create group",
|
||||
Long: `Creates new group:
|
||||
{
|
||||
"Name":<group_name>,
|
||||
"Description":<description>,
|
||||
@ -27,7 +26,7 @@ var cmdGroups = []cobra.Command{
|
||||
Metadata - JSON structured string`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
var group mfxsdk.Group
|
||||
@ -43,21 +42,21 @@ var cmdGroups = []cobra.Command{
|
||||
logCreated(id)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get [all | children <group_id> | parents <group_id> | group_id] <user_auth_token>",
|
||||
{
|
||||
Use: "get [all | children <group_id> | parents <group_id> | <group_id>] <user_auth_token>",
|
||||
Short: "Get group",
|
||||
Long: `Get all users groups, group children or group by id.
|
||||
all - lists all groups
|
||||
children <group_id> - lists all children groups of <group_id>
|
||||
<group_id> - shows group with provided group ID`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
if args[0] == "all" {
|
||||
if len(args) > 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
l, err := sdk.Groups(uint64(Offset), uint64(Limit), args[1])
|
||||
@ -70,7 +69,7 @@ var cmdGroups = []cobra.Command{
|
||||
}
|
||||
if args[0] == "children" {
|
||||
if len(args) > 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
l, err := sdk.Children(args[1], uint64(Offset), uint64(Limit), args[2])
|
||||
@ -83,7 +82,7 @@ var cmdGroups = []cobra.Command{
|
||||
}
|
||||
if args[0] == "parents" {
|
||||
if len(args) > 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
l, err := sdk.Parents(args[1], uint64(Offset), uint64(Limit), args[2])
|
||||
@ -95,7 +94,7 @@ var cmdGroups = []cobra.Command{
|
||||
return
|
||||
}
|
||||
if len(args) > 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
t, err := sdk.Group(args[0], args[1])
|
||||
@ -106,14 +105,14 @@ var cmdGroups = []cobra.Command{
|
||||
logJSON(t)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "assign",
|
||||
Short: "assign <member_ids> <member_type> <group_id> <user_auth_token>",
|
||||
{
|
||||
Use: "assign <member_ids> <member_type> <group_id> <user_auth_token>",
|
||||
Short: "Assign member",
|
||||
Long: `Assign members to a group.
|
||||
member_ids - '["member_id",...]`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
var ids []string
|
||||
@ -128,14 +127,14 @@ var cmdGroups = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "unassign",
|
||||
Short: "unassign <member_ids> <group_id> <user_auth_token>",
|
||||
{
|
||||
Use: "unassign <member_ids> <group_id> <user_auth_token>",
|
||||
Short: "Unassign member",
|
||||
Long: `Unassign members from a group
|
||||
member_ids - '["member_id",...]`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
var ids []string
|
||||
@ -150,13 +149,13 @@ var cmdGroups = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "delete <group_id> <user_auth_token>",
|
||||
{
|
||||
Use: "delete <group_id> <user_auth_token>",
|
||||
Short: "Delete group",
|
||||
Long: `Delete group.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
if err := sdk.DeleteGroup(args[0], args[1]); err != nil {
|
||||
@ -166,13 +165,13 @@ var cmdGroups = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "members",
|
||||
Short: "members <group_id> <user_auth_token>",
|
||||
{
|
||||
Use: "members <group_id> <user_auth_token>",
|
||||
Short: "Members list",
|
||||
Long: `Lists all members of a group.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
up, err := sdk.Members(args[0], args[1], uint64(Offset), uint64(Limit))
|
||||
@ -183,13 +182,13 @@ var cmdGroups = []cobra.Command{
|
||||
logJSON(up)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "membership",
|
||||
Short: "membership <member_id> <user_auth_token>",
|
||||
{
|
||||
Use: "membership <member_id> <user_auth_token>",
|
||||
Short: "Membership list",
|
||||
Long: `List member group's membership`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
up, err := sdk.Memberships(args[0], args[1], uint64(Offset), uint64(Limit))
|
||||
@ -205,15 +204,14 @@ var cmdGroups = []cobra.Command{
|
||||
// NewGroupsCmd returns users command.
|
||||
func NewGroupsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "groups",
|
||||
Use: "groups [create | get | delete | assign | unassign | members | membership]",
|
||||
Short: "Groups management",
|
||||
Long: `Groups management: create groups and assigns member to groups"`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("groups [create | get | delete | assign | unassign | members | membership]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdGroups {
|
||||
cmd.AddCommand(&cmdGroups[i])
|
||||
}
|
||||
|
||||
return &cmd
|
||||
}
|
||||
|
23
cli/keys.go
23
cli/keys.go
@ -11,12 +11,12 @@ import (
|
||||
|
||||
var cmdAPIKeys = []cobra.Command{
|
||||
{
|
||||
Use: "issue",
|
||||
Short: "issue <duration> <user_auth_token>",
|
||||
Use: "issue <duration> <user_auth_token>",
|
||||
Short: "Issue key",
|
||||
Long: `Issues a new Key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,12 +36,12 @@ var cmdAPIKeys = []cobra.Command{
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "revoke",
|
||||
Short: "revoke <key_id> <user_auth_token>",
|
||||
Use: "revoke <key_id> <user_auth_token>",
|
||||
Short: "Revoke key",
|
||||
Long: `Removes API key from database`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -54,12 +54,12 @@ var cmdAPIKeys = []cobra.Command{
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "retrieve",
|
||||
Short: "retrieve <key_id> <user_auth_token>",
|
||||
Use: "retrieve <key_id> <user_auth_token>",
|
||||
Short: "Retrieve key",
|
||||
Long: `Retrieves API key with given id`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -77,12 +77,9 @@ var cmdAPIKeys = []cobra.Command{
|
||||
// NewKeysCmd returns keys command.
|
||||
func NewKeysCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "keys",
|
||||
Use: "keys [issue | revoke | retrieve]",
|
||||
Short: "Keys management",
|
||||
Long: `Keys management: issue, revoke, or retrieve API key.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("keys [issue | revoke | retrieve]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdAPIKeys {
|
||||
|
@ -7,12 +7,12 @@ import "github.com/spf13/cobra"
|
||||
|
||||
var cmdMessages = []cobra.Command{
|
||||
{
|
||||
Use: "send",
|
||||
Short: "send <channel_id>[.<subtopic>...] <JSON_string> <thing_key>",
|
||||
Use: "send <channel_id.subtopic> <JSON_string> <thing_key>",
|
||||
Short: "Send messages",
|
||||
Long: `Sends message on the channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -25,12 +25,12 @@ var cmdMessages = []cobra.Command{
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "read",
|
||||
Short: "read <channel_id>[.<subtopic>...] <thing_key>",
|
||||
Use: "read <channel_id.subtopic> <thing_key>",
|
||||
Short: "Read messages",
|
||||
Long: `Reads all channel messages`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -48,12 +48,9 @@ var cmdMessages = []cobra.Command{
|
||||
// NewMessagesCmd returns messages command.
|
||||
func NewMessagesCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "messages",
|
||||
Use: "messages [send | read]",
|
||||
Short: "Send or read messages",
|
||||
Long: `Send or read messages using the http-adapter and the configured database reader`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("messages [send | read]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdMessages {
|
||||
|
@ -24,12 +24,12 @@ const csvExt = ".csv"
|
||||
|
||||
var cmdProvision = []cobra.Command{
|
||||
{
|
||||
Use: "things",
|
||||
Short: "things <things_file> <user_token>",
|
||||
Use: "things <things_file> <user_token>",
|
||||
Short: "Provision things",
|
||||
Long: `Bulk create things`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -54,12 +54,12 @@ var cmdProvision = []cobra.Command{
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "channels",
|
||||
Short: "channels <channels_file> <user_token>",
|
||||
Use: "channels <channels_file> <user_token>",
|
||||
Short: "Provision channels",
|
||||
Long: `Bulk create channels`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -79,12 +79,12 @@ var cmdProvision = []cobra.Command{
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "connect",
|
||||
Short: "connect <connections_file> <user_token>",
|
||||
Use: "connect <connections_file> <user_token>",
|
||||
Short: "Provision connections",
|
||||
Long: `Bulk connect things to channels`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ var cmdProvision = []cobra.Command{
|
||||
channels := []mfxsdk.Channel{}
|
||||
|
||||
if len(args) != 0 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ var cmdProvision = []cobra.Command{
|
||||
// NewProvisionCmd returns provision command.
|
||||
func NewProvisionCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "provision",
|
||||
Use: "provision [things | channels | connect | test]",
|
||||
Short: "Provision things and channels from a config file",
|
||||
Long: `Provision things and channels: use json or csv file to bulk provision things and channels`,
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ import (
|
||||
)
|
||||
|
||||
var cmdThings = []cobra.Command{
|
||||
cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create <JSON_thing> <user_auth_token>",
|
||||
{
|
||||
Use: "create <JSON_thing> <user_auth_token>",
|
||||
Short: "Create thing",
|
||||
Long: `Create new thing, generate his UUID and store it`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,13 +36,13 @@ var cmdThings = []cobra.Command{
|
||||
logCreated(id)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get [all | <thing_id>] <user_auth_token>",
|
||||
Long: `Get all things or thing by id`,
|
||||
{
|
||||
Use: "get [all | <thing_id>] <user_auth_token>",
|
||||
Short: "Get things",
|
||||
Long: `Get a list of things or thing by id`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -65,13 +65,13 @@ var cmdThings = []cobra.Command{
|
||||
logJSON(t)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "delete <thing_id> <user_auth_token>",
|
||||
{
|
||||
Use: "delete <thing_id> <user_auth_token>",
|
||||
Short: "Delete thing",
|
||||
Long: `Removes thing from database`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -83,13 +83,13 @@ var cmdThings = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "update",
|
||||
Short: "update <JSON_string> <user_auth_token>",
|
||||
{
|
||||
Use: "update <JSON_string> <user_auth_token>",
|
||||
Short: "Update thing",
|
||||
Long: `Update thing record`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -107,13 +107,13 @@ var cmdThings = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "connect",
|
||||
Short: "connect <thing_id> <channel_id> <user_auth_token>",
|
||||
{
|
||||
Use: "connect <thing_id> <channel_id> <user_auth_token>",
|
||||
Short: "Connect thing",
|
||||
Long: `Connect thing to the channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -129,13 +129,13 @@ var cmdThings = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "disconnect",
|
||||
Short: "disconnect <thing_id> <channel_id> <user_auth_token>",
|
||||
{
|
||||
Use: "disconnect <thing_id> <channel_id> <user_auth_token>",
|
||||
Short: "Disconnect thing",
|
||||
Long: `Disconnect thing to the channel`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -147,13 +147,13 @@ var cmdThings = []cobra.Command{
|
||||
logOK()
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "connections",
|
||||
Short: "connections <thing_id> <user_auth_token>",
|
||||
{
|
||||
Use: "connections <thing_id> <user_auth_token>",
|
||||
Short: "Connected list",
|
||||
Long: `List of Channels connected to Thing`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -166,13 +166,13 @@ var cmdThings = []cobra.Command{
|
||||
logJSON(cl)
|
||||
},
|
||||
},
|
||||
cobra.Command{
|
||||
Use: "not-connected",
|
||||
Short: "not-connected <thing_id> <user_auth_token>",
|
||||
{
|
||||
Use: "not-connected <thing_id> <user_auth_token>",
|
||||
Short: "Not-connected list",
|
||||
Long: `List of Channels not connected to a Thing`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -190,12 +190,9 @@ var cmdThings = []cobra.Command{
|
||||
// NewThingsCmd returns things command.
|
||||
func NewThingsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "things",
|
||||
Use: "things [create | get | update | delete | connect | disconnect | connections | not-connected]",
|
||||
Short: "Things management",
|
||||
Long: `Things management: create, get, update or delete Thing, connect or disconnect Thing from Channel and get the list of Channels connected or disconnected from a Thing`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("things [create | get | update | delete | connect | disconnect | connections | not-connected]")
|
||||
},
|
||||
}
|
||||
|
||||
for i := range cmdThings {
|
||||
|
71
cli/users.go
71
cli/users.go
@ -10,15 +10,14 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewUsersCmd returns users command.
|
||||
func NewUsersCmd() *cobra.Command {
|
||||
createCmd := cobra.Command{
|
||||
Use: "create",
|
||||
Short: "create <username> <password> <user_auth_token>",
|
||||
var cmdUsers = []cobra.Command{
|
||||
{
|
||||
Use: "create <username> <password> <user_auth_token>",
|
||||
Short: "Create user",
|
||||
Long: `Creates new user`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 2 || len(args) > 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
if len(args) == 2 {
|
||||
@ -37,15 +36,14 @@ func NewUsersCmd() *cobra.Command {
|
||||
|
||||
logCreated(id)
|
||||
},
|
||||
}
|
||||
|
||||
getCmd := cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get <user_auth_token>",
|
||||
},
|
||||
{
|
||||
Use: "get <user_auth_token>",
|
||||
Short: "Get user",
|
||||
Long: `Returns user object`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -57,15 +55,14 @@ func NewUsersCmd() *cobra.Command {
|
||||
|
||||
logJSON(u)
|
||||
},
|
||||
}
|
||||
|
||||
tokenCmd := cobra.Command{
|
||||
Use: "token",
|
||||
Short: "token <username> <password>",
|
||||
Long: `Creates new token`,
|
||||
},
|
||||
{
|
||||
Use: "token <username> <password>",
|
||||
Short: "Get token",
|
||||
Long: `Generate new token`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -82,15 +79,14 @@ func NewUsersCmd() *cobra.Command {
|
||||
logCreated(token)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
updateCmd := cobra.Command{
|
||||
Use: "update",
|
||||
Short: "update <JSON_string> <user_auth_token>",
|
||||
},
|
||||
{
|
||||
Use: "update <JSON_string> <user_auth_token>",
|
||||
Short: "Update user",
|
||||
Long: `Update user metadata`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -107,15 +103,14 @@ func NewUsersCmd() *cobra.Command {
|
||||
|
||||
logOK()
|
||||
},
|
||||
}
|
||||
|
||||
passwordCmd := cobra.Command{
|
||||
Use: "password",
|
||||
Short: "password <old_password> <password> <user_auth_token>",
|
||||
},
|
||||
{
|
||||
Use: "password <old_password> <password> <user_auth_token>",
|
||||
Short: "Update password",
|
||||
Long: `Update user password`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Short)
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
@ -126,19 +121,15 @@ func NewUsersCmd() *cobra.Command {
|
||||
|
||||
logOK()
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// NewUsersCmd returns users command.
|
||||
func NewUsersCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "users",
|
||||
Use: "users [create | get | update | token | password]",
|
||||
Short: "Users management",
|
||||
Long: `Users management: create accounts and tokens"`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logUsage("users [create | get | update | token | password]")
|
||||
},
|
||||
}
|
||||
|
||||
cmdUsers := []cobra.Command{
|
||||
createCmd, getCmd, tokenCmd, updateCmd, passwordCmd,
|
||||
}
|
||||
|
||||
for i := range cmdUsers {
|
||||
|
@ -70,7 +70,7 @@ func main() {
|
||||
"auth-url",
|
||||
"a",
|
||||
sdkConf.AuthURL,
|
||||
"Mainflux Auth URL",
|
||||
"Auth service URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -78,7 +78,7 @@ func main() {
|
||||
"bootstrap-url",
|
||||
"b",
|
||||
sdkConf.BootstrapURL,
|
||||
"Mainflux Bootstrap URL",
|
||||
"Bootstrap service URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -86,7 +86,7 @@ func main() {
|
||||
"certs-url",
|
||||
"e",
|
||||
sdkConf.CertsURL,
|
||||
"Mainflux Certs URL",
|
||||
"Certs service URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -94,7 +94,7 @@ func main() {
|
||||
"things-url",
|
||||
"t",
|
||||
sdkConf.ThingsURL,
|
||||
"Mainflux Things URL",
|
||||
"Things service URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -102,7 +102,7 @@ func main() {
|
||||
"users-url",
|
||||
"u",
|
||||
sdkConf.UsersURL,
|
||||
"Mainflux Users URL",
|
||||
"Users service URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -110,7 +110,7 @@ func main() {
|
||||
"http-url",
|
||||
"p",
|
||||
sdkConf.HTTPAdapterURL,
|
||||
"Mainflux message content type",
|
||||
"HTTP adapter URL",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -118,7 +118,7 @@ func main() {
|
||||
"content-type",
|
||||
"y",
|
||||
msgContentType,
|
||||
"Mainflux message content type",
|
||||
"Message content type",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
@ -134,7 +134,7 @@ func main() {
|
||||
"config",
|
||||
"c",
|
||||
cli.ConfigPath,
|
||||
"Mainflux config path",
|
||||
"Config path",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
@ -151,7 +151,7 @@ func main() {
|
||||
"limit",
|
||||
"l",
|
||||
100,
|
||||
"limit query parameter",
|
||||
"Limit query parameter",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().UintVarP(
|
||||
@ -159,7 +159,7 @@ func main() {
|
||||
"offset",
|
||||
"o",
|
||||
0,
|
||||
"offset query parameter",
|
||||
"Offset query parameter",
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(
|
||||
@ -167,7 +167,7 @@ func main() {
|
||||
"name",
|
||||
"n",
|
||||
"",
|
||||
"name query parameter",
|
||||
"Name query parameter",
|
||||
)
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user