Feature: CLI flag to print all help command in tree hierarchy
arvindh123 opened this issue · comments
Is your feature request related to a problem? Please describe.
No
Describe the feature you are requesting, as well as the possible use case(s) for it.
A CLI flag to print all help command in tree hierarchy , This will give overview of all available commands with CLI.
Some thing like below
$ build/cli --help-tree
magistrala-cli:
bootstrap [create | get | update | remove | bootstrap | whitelist]: Bootstrap management
bootstrap [<external_id> <external_key> | secure <external_id> <external_key> <crypto_key> ]: Bootstrap config
create <JSON_config> <user_auth_token>: Create config
get [all | <thing_id>] <user_auth_token>: Get config
remove <thing_id> <user_auth_token>: Remove config
update [config <JSON_config> | connection <id> <channel_ids> | certs <id> <client_cert> <client_key> <ca> ] <user_auth_token>: Update config
whitelist <JSON_config> <user_auth_token>: Whitelist config
certs [issue | get | revoke ]: Certificates management
get [<cert_serial> | thing <thing_id> ] <user_auth_token>: Get certificate
issue <thing_id> <user_auth_token> [--ttl=8760h]: Issue certificate
revoke <thing_id> <user_auth_token>: Revoke certificate
channels [create | get | update | delete | connections | not-connected | assign | unassign | users | groups]: Channels management
assign [users | groups]: Assign users or groups to a channel
groups <group_ids> <channel_id> <user_auth_token>: Assign groups
users <relation> <user_ids> <channel_id> <user_auth_token>: Assign users
connections <channel_id> <user_auth_token>: Connections list
create <JSON_channel> <user_auth_token>: Create channel
delete <channel_id> <user_auth_token>: Delete channel
disable <channel_id> <user_auth_token>: Change channel status to disabled
enable <channel_id> <user_auth_token>: Change channel status to enabled
get [all | <channel_id>] <user_auth_token>: Get channel
groups <channel_id> <user_auth_token>: List groups
unassign [users | groups]: Unassign users or groups from a channel
groups <group_ids> <channel_id> <user_auth_token>: Unassign groups
users <relation> <user_ids> <channel_id> <user_auth_token>: Unassign users
update <channel_id> <JSON_string> <user_auth_token>: Update channel
users <channel_id> <user_auth_token>: List users
config <key> <value>: CLI local config
domains [create | get | update | enable | disable | enable | users | assign | unassign]: Domains management
assign [users]: Assign users to a domain
users <relation> <user_ids> <domain_id> <token>: Assign users
create <name> <alias> <token>: Create Domain
disable <domain_id> <token>: Change domain status to disabled
enable <domain_id> <token>: Change domain status to enabled
get [all | <domain_id> ] <token>: Get Domains
unassign [users]: Unassign users from a domain
users <relation> <user_ids> <domain_id> <token>: Unassign users
update <domain_id> <JSON_string> <user_auth_token>: Update domains
users <domain_id> <token>: List Domain users
groups [create | get | update | delete | assign | unassign | users | channels ]: Groups management
assign [users]: Assign users to a group
users <relation> <user_ids> <group_id> <user_auth_token>: Assign users
channels <group_id> <user_auth_token>: List channels
create <JSON_group> <user_auth_token>: Create group
delete <group_id> <user_auth_token>: Delete group
disable <group_id> <user_auth_token>: Change group status to disabled
enable <group_id> <user_auth_token>: Change group status to enabled
get [all | children <group_id> | parents <group_id> | members <group_id> | <group_id>] <user_auth_token>: Get group
unassign [users]: Unassign users from a group
users <relation> <user_ids> <group_id> <user_auth_token>: Unassign users
update <JSON_group> <user_auth_token>: Update group
users <group_id> <user_auth_token>: List users
health <service>: Health Check
invitations [send | get | accept | delete]: Invitations management
accept <domain_id> <user_auth_token>: Accept invitation
delete <user_id> <domain_id> <user_auth_token>: Delete invitation
get [all | <user_id> <domain_id> ] <user_auth_token>: Get invitations
send <user_id> <domain_id> <relation> <user_auth_token>: Send invitation
messages [send | read]: Send or read messages
read <channel_id.subtopic> <user_token>: Read messages
send <channel_id.subtopic> <JSON_string> <thing_key>: Send messages
provision [things | channels | connect | test]: Provision things and channels from a config file
channels <channels_file> <user_token>: Provision channels
connect <connections_file> <user_token>: Provision connections
test: test
things <things_file> <user_token>: Provision things
subscription [create | get | remove ]: Subscription management
create <topic> <contact> <user_auth_token>: Create subscription
get [all | <sub_id>] <user_auth_token>: Get subscription
remove <sub_id> <user_auth_token>: Remove subscription
things [create | get | update | delete | share | connect | disconnect | connections | not-connected | users ]: Things management
connect <thing_id> <channel_id> <user_auth_token>: Connect thing
connections <thing_id> <user_auth_token>: Connected list
create <JSON_thing> <user_auth_token>: Create thing
delete <thing_id> <user_auth_token>: Delete thing
disable <thing_id> <user_auth_token>: Change thing status to disabled
disconnect <thing_id> <channel_id> <user_auth_token>: Disconnect thing
enable <thing_id> <user_auth_token>: Change thing status to enabled
get [all | <thing_id>] <user_auth_token>: Get things
identify <thing_key>: Identify thing
share <thing_id> <user_id> <relation> <user_auth_token>: Share thing with a user
unshare <thing_id> <user_id> <relation> <user_auth_token>: Unshare thing with a user
update [<thing_id> <JSON_string> | tags <thing_id> <tags> | secret <thing_id> <secret> ] <user_auth_token>: Update thing
users <thing_id> <user_auth_token>: List users
users [create | get | update | token | password | enable | disable | channels | things | groups]: Users management
channels <user_id> <user_auth_token>: List channels
create <name> <username> <password> <user_auth_token>: Create user
disable <user_id> <user_auth_token>: Change user status to disabled
domains <user_id> <user_auth_token>: List domains
enable <user_id> <user_auth_token>: Change user status to enabled
get [all | <user_id> ] <user_auth_token>: Get users
groups <user_id> <user_auth_token>: List groups
password <old_password> <password> <user_auth_token>: Update password
profile <user_auth_token>: Get user profile
refreshtoken <token> [<domainID>]: Get token
resetpassword <password> <confpass> <password_request_token>: Reset password
resetpasswordrequest <email>: Send reset password request
things <user_id> <user_auth_token>: List things
token <username> <password> [<domainID>]: Get token
update [<user_id> <JSON_string> | tags <user_id> <tags> | identity <user_id> <identity> ] <user_auth_token>: Update user
Indicate the importance of this feature to you.
Must-have
Anything else?
Implementation Idea:
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "myapp",
Short: "My application does amazing things",
}
var printTree bool
func main() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().BoolVar(&printTree, "help-tree", false, "Print the command tree")
// Add subcommands here
rootCmd.AddCommand(cmd1)
rootCmd.AddCommand(cmd2)
rootCmd.AddCommand(cmd3)
if printTree {
printCommandTree(rootCmd, "")
return
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func initConfig() {
// Initialize configuration if needed
}
var cmd1 = &cobra.Command{
Use: "cmd1",
Short: "Command 1",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Command 1 executed")
},
}
var cmd2 = &cobra.Command{
Use: "cmd2",
Short: "Command 2",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Command 2 executed")
},
}
var cmd3 = &cobra.Command{
Use: "cmd3",
Short: "Command 3",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Command 3 executed")
},
}
func printCommandTree(cmd *cobra.Command, indent string) {
fmt.Println(indent + cmd.Use + ": " + cmd.Short)
for _, c := range cmd.Commands() {
printCommandTree(c, indent+" ")
}
}