From 95a88dc154f0937c80ea84991e8bf9bc9dfc1e31 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 17:46:41 -0300 Subject: [PATCH 01/28] feat: add script for the command page generation --- internal/docs/cmd_page.go | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 internal/docs/cmd_page.go diff --git a/internal/docs/cmd_page.go b/internal/docs/cmd_page.go new file mode 100644 index 0000000..ee460dc --- /dev/null +++ b/internal/docs/cmd_page.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "log" + "os" + "strings" + + "github.com/latitudesh/lsh/cli" + "github.com/spf13/cobra" +) + +const Ignored = 0 +const General = 1 + +func main() { + f, err := os.Create("commands.md") + if err != nil { + log.Fatal(err) + } + defer f.Close() + + rootCmd, err := cli.MakeRootCmd() + if err != nil { + log.Fatal("Cmd construction error: ", err) + os.Exit(1) + } + + for _, c := range rootCmd.Commands() { + cmdSection := buildSection(c) + f.WriteString(cmdSection) + } +} + +func buildSection(cmd *cobra.Command) string { + var section strings.Builder + header := fmt.Sprintf("## %s\n", cmd.Name()) + section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) + + for _, subCmd := range cmd.Commands() { + section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s\n```\n", cmd.Name(), subCmd.Name())) + } + return section.String() +} From ba9e6b63fe9531b0dd46469f78b4a979ba3389f5 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 17:50:46 -0300 Subject: [PATCH 02/28] chore: adjustments to servers subcommands descriptions --- cli/create_server_operation.go | 2 +- cli/create_server_reinstall_operation.go | 3 ++- cli/destroy_server_operation.go | 2 +- cli/get_server_operation.go | 2 +- cli/get_servers_operation.go | 3 ++- cli/server_schedule_deletion_operation.go | 3 ++- cli/server_unschedule_deletion_operation.go | 3 ++- cli/update_server_operation.go | 3 ++- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cli/create_server_operation.go b/cli/create_server_operation.go index f53cb8b..36f08ec 100755 --- a/cli/create_server_operation.go +++ b/cli/create_server_operation.go @@ -27,7 +27,7 @@ type CreateServerOperation struct { func (o *CreateServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: "Deploy a new server.", + Short: "Deploy a bare metal server.", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/create_server_reinstall_operation.go b/cli/create_server_reinstall_operation.go index 0e8fd49..14af11a 100755 --- a/cli/create_server_reinstall_operation.go +++ b/cli/create_server_reinstall_operation.go @@ -31,7 +31,8 @@ type CreateServerReinstallOperation struct { func (o *CreateServerReinstallOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "reinstall", - Short: "Submit a reinstall request to a server.", + Short: "Reintall a server.", + Long: "Submit a reinstall request to a server.", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/destroy_server_operation.go b/cli/destroy_server_operation.go index 015f3c5..7a30fc7 100755 --- a/cli/destroy_server_operation.go +++ b/cli/destroy_server_operation.go @@ -26,7 +26,7 @@ type DestroyServerOperation struct { func (o *DestroyServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: "Remove a server.", + Short: "Delete a server.", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_server_operation.go b/cli/get_server_operation.go index 122d77f..5bb6408 100755 --- a/cli/get_server_operation.go +++ b/cli/get_server_operation.go @@ -16,7 +16,7 @@ import ( func makeOperationServersGetServerCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: `Returns a server that belongs to the team.`, + Short: "Get information on a server.", RunE: runOperationServersGetServer, } diff --git a/cli/get_servers_operation.go b/cli/get_servers_operation.go index 2ce76a4..a02613d 100755 --- a/cli/get_servers_operation.go +++ b/cli/get_servers_operation.go @@ -16,7 +16,8 @@ import ( func makeOperationServersGetServersCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Returns a list of all servers belonging to the team.`, + Short: "List servers", + Long: `Returns a list of all servers belonging to the team.`, RunE: runOperationServersGetServers, } diff --git a/cli/server_schedule_deletion_operation.go b/cli/server_schedule_deletion_operation.go index b06826d..aec2880 100755 --- a/cli/server_schedule_deletion_operation.go +++ b/cli/server_schedule_deletion_operation.go @@ -26,7 +26,8 @@ type ScheduleServerDeletionOperation struct { func (o *ScheduleServerDeletionOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "schedule-deletion", - Short: "Schedules the server to be removed at the end of the billing cycle.", + Short: "Schedule deletion", + Long: "Schedules the server to be removed at the end of the billing cycle.", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/server_unschedule_deletion_operation.go b/cli/server_unschedule_deletion_operation.go index 14b33db..cc074a7 100755 --- a/cli/server_unschedule_deletion_operation.go +++ b/cli/server_unschedule_deletion_operation.go @@ -26,7 +26,8 @@ type UnscheduleServerDeletionOperation struct { func (o *UnscheduleServerDeletionOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "unschedule-deletion", - Short: "Unschedules the server removal at the end of the billing cycle.", + Short: "Unschedule deletion", + Long: "Unschedules the server removal at the end of the billing cycle.", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/update_server_operation.go b/cli/update_server_operation.go index d67326e..f8bc152 100755 --- a/cli/update_server_operation.go +++ b/cli/update_server_operation.go @@ -31,7 +31,8 @@ type UpdateServerOperation struct { func (o *UpdateServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: "Update server information.", + Short: "Update a server.", + Long: "Update server information.", RunE: o.run, PreRun: o.preRun, } From 7323d7920e99b89a3826440103eefbb4045b0807 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 17:59:33 -0300 Subject: [PATCH 03/28] chore: adjustments to api_keys subcommands descriptions --- cli/delete_api_key_operation.go | 3 ++- cli/get_api_keys_operation.go | 3 ++- cli/post_api_key_operation.go | 3 ++- cli/update_api_key_operation.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/delete_api_key_operation.go b/cli/delete_api_key_operation.go index 4cb02a3..04621e4 100755 --- a/cli/delete_api_key_operation.go +++ b/cli/delete_api_key_operation.go @@ -26,7 +26,8 @@ type DeleteAPIKeyOperation struct { func (o *DeleteAPIKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: `Delete an existing API Key. Once deleted, the API Key can no longer be used to access the API.`, + Short: "Delete an API Key", + Long: `Delete an existing API Key. Once deleted, the API Key can no longer be used to access the API.`, RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_api_keys_operation.go b/cli/get_api_keys_operation.go index f23cdc3..c1739d6 100755 --- a/cli/get_api_keys_operation.go +++ b/cli/get_api_keys_operation.go @@ -14,7 +14,8 @@ import ( func makeOperationAPIKeysGetAPIKeysCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Returns a list of all API keys from the team members`, + Short: "List API Keys", + Long: `Returns a list of all API keys from the team members.`, RunE: runOperationAPIKeysGetAPIKeys, } diff --git a/cli/post_api_key_operation.go b/cli/post_api_key_operation.go index c743e12..5a2d23e 100755 --- a/cli/post_api_key_operation.go +++ b/cli/post_api_key_operation.go @@ -26,7 +26,8 @@ type CreateAPIKeyOperation struct { func (o *CreateAPIKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: `Create a new API Key that is tied to the current user account. The created API key is only listed ONCE upon creation. It can however be regenerated or deleted.`, + Short: "Create an API Key", + Long: `Create a new API Key that is tied to the current user account. The created API key is only listed ONCE upon creation. It can however be regenerated or deleted.`, RunE: o.run, PreRun: o.preRun, } diff --git a/cli/update_api_key_operation.go b/cli/update_api_key_operation.go index 2a2c122..1177c61 100755 --- a/cli/update_api_key_operation.go +++ b/cli/update_api_key_operation.go @@ -27,7 +27,8 @@ type UpdateAPIKeyOperation struct { func (o *UpdateAPIKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: `Regenerate an existing API Key that is tied to the current user. This overrides the previous key.`, + Short: "Update an API Key", + Long: `Regenerate an existing API Key that is tied to the current user. This overrides the previous key.`, RunE: o.run, PreRun: o.preRun, } From fdf2b51bd4fc77954cd210b12358ebd2fb1a092b Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:03:02 -0300 Subject: [PATCH 04/28] chore: remove dots from server docs --- cli/create_server_operation.go | 2 +- cli/create_server_reinstall_operation.go | 2 +- cli/destroy_server_operation.go | 2 +- cli/get_server_operation.go | 2 +- cli/update_server_operation.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/create_server_operation.go b/cli/create_server_operation.go index 36f08ec..3b92cd0 100755 --- a/cli/create_server_operation.go +++ b/cli/create_server_operation.go @@ -27,7 +27,7 @@ type CreateServerOperation struct { func (o *CreateServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: "Deploy a bare metal server.", + Short: "Deploy a bare metal server", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/create_server_reinstall_operation.go b/cli/create_server_reinstall_operation.go index 14af11a..939cccd 100755 --- a/cli/create_server_reinstall_operation.go +++ b/cli/create_server_reinstall_operation.go @@ -31,7 +31,7 @@ type CreateServerReinstallOperation struct { func (o *CreateServerReinstallOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "reinstall", - Short: "Reintall a server.", + Short: "Reintall a server", Long: "Submit a reinstall request to a server.", RunE: o.run, PreRun: o.preRun, diff --git a/cli/destroy_server_operation.go b/cli/destroy_server_operation.go index 7a30fc7..8c87f39 100755 --- a/cli/destroy_server_operation.go +++ b/cli/destroy_server_operation.go @@ -26,7 +26,7 @@ type DestroyServerOperation struct { func (o *DestroyServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: "Delete a server.", + Short: "Delete a server", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_server_operation.go b/cli/get_server_operation.go index 5bb6408..094e95f 100755 --- a/cli/get_server_operation.go +++ b/cli/get_server_operation.go @@ -16,7 +16,7 @@ import ( func makeOperationServersGetServerCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: "Get information on a server.", + Short: "Get information on a server", RunE: runOperationServersGetServer, } diff --git a/cli/update_server_operation.go b/cli/update_server_operation.go index f8bc152..516f0fe 100755 --- a/cli/update_server_operation.go +++ b/cli/update_server_operation.go @@ -31,7 +31,7 @@ type UpdateServerOperation struct { func (o *UpdateServerOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: "Update a server.", + Short: "Update a server", Long: "Update server information.", RunE: o.run, PreRun: o.preRun, From 9462eba516d6f6ec79739f543ef624fcd6910150 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:07:49 -0300 Subject: [PATCH 05/28] chore: adjustments to plans subcommands descriptions --- cli/get_bandwidth_plans_operation.go | 2 +- cli/get_plan_operation.go | 2 +- cli/get_plans_operation.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/get_bandwidth_plans_operation.go b/cli/get_bandwidth_plans_operation.go index 1646c61..9c9c186 100755 --- a/cli/get_bandwidth_plans_operation.go +++ b/cli/get_bandwidth_plans_operation.go @@ -16,7 +16,7 @@ import ( func makeOperationPlansGetBandwidthPlansCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list-bandwidth", - Short: `Lists all bandwidth plans.`, + Short: "List bandwidth package plans", RunE: runOperationPlansGetBandwidthPlans, } diff --git a/cli/get_plan_operation.go b/cli/get_plan_operation.go index ba6fbdc..b8ae7c6 100755 --- a/cli/get_plan_operation.go +++ b/cli/get_plan_operation.go @@ -16,7 +16,7 @@ import ( func makeOperationPlansGetPlanCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: `Returns a plan`, + Short: "Retrieve information of a plan", RunE: runOperationPlansGetPlan, } diff --git a/cli/get_plans_operation.go b/cli/get_plans_operation.go index a9b2561..d64b055 100755 --- a/cli/get_plans_operation.go +++ b/cli/get_plans_operation.go @@ -17,7 +17,7 @@ import ( func makeOperationPlansGetPlansCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Lists all plans. Availability by region is included in ` + "`" + `attributes.regions.locations.available[*]` + "`" + ` node for a given plan.`, + Short: "List available plans", RunE: runOperationPlansGetPlans, } From 0bf2a9c130d7960c6118846770d1865c64a64ae0 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:15:32 -0300 Subject: [PATCH 06/28] chore: adjustments to projects subcommands descriptions --- cli/create_project_operation.go | 2 +- cli/delete_project_operation.go | 3 ++- cli/get_project_operation.go | 3 ++- cli/get_projects_operation.go | 3 ++- cli/update_project_operation.go | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/create_project_operation.go b/cli/create_project_operation.go index 4805d41..5bcf9a9 100755 --- a/cli/create_project_operation.go +++ b/cli/create_project_operation.go @@ -27,7 +27,7 @@ type CreateProjectOperation struct { func (o *CreateProjectOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: "Creates a project.", + Short: "Create a project", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/delete_project_operation.go b/cli/delete_project_operation.go index 690c3f6..4844c0b 100755 --- a/cli/delete_project_operation.go +++ b/cli/delete_project_operation.go @@ -26,7 +26,8 @@ func makeOperationProjectsDeleteProjectCmd() (*cobra.Command, error) { func (o *DeleteProjectOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: `Deletes a project from the current team`, + Short: "Delete a project", + Long: `Deletes a project from the current team.`, RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_project_operation.go b/cli/get_project_operation.go index 5f15b00..bc51db4 100755 --- a/cli/get_project_operation.go +++ b/cli/get_project_operation.go @@ -18,7 +18,8 @@ import ( func makeOperationProjectsGetProjectCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: `Returns a project from the current team`, + Short: "Retrieve a project", + Long: `Returns a project from the current team.`, RunE: runOperationProjectsGetProject, } diff --git a/cli/get_projects_operation.go b/cli/get_projects_operation.go index 46f5ada..71687ae 100755 --- a/cli/get_projects_operation.go +++ b/cli/get_projects_operation.go @@ -16,7 +16,8 @@ import ( func makeOperationProjectsGetProjectsCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Returns a list of all projects for the current team`, + Short: "List projects", + Long: `Returns a list of all projects for the current team.`, RunE: runOperationProjectsGetProjects, } diff --git a/cli/update_project_operation.go b/cli/update_project_operation.go index 57cc74b..6d00bb1 100755 --- a/cli/update_project_operation.go +++ b/cli/update_project_operation.go @@ -34,7 +34,7 @@ type UpdateProjectOperation struct { func (o *UpdateProjectOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: "Updates a project.", + Short: "Update a project", RunE: o.run, PreRun: o.preRun, } From c71bf43d75f17e91d4448073488fbd1a24c711bd Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:25:46 -0300 Subject: [PATCH 07/28] chore: adjustments to ssh_keys subcommands descriptions --- cli/delete_project_ssh_key_operation.go | 3 ++- cli/get_project_ssh_key_operation.go | 3 ++- cli/get_project_ssh_keys_operation.go | 3 ++- cli/post_project_ssh_key_operation.go | 3 ++- cli/put_project_ssh_key_operation.go | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cli/delete_project_ssh_key_operation.go b/cli/delete_project_ssh_key_operation.go index e02ada7..3fe4ab3 100755 --- a/cli/delete_project_ssh_key_operation.go +++ b/cli/delete_project_ssh_key_operation.go @@ -26,7 +26,8 @@ type DeleteSSHKeyOperation struct { func (o *DeleteSSHKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: `Allow you remove SSH Keys in a project. Remove a SSH Key from the project won't revoke the SSH Keys access for previously deploy and reinstall actions.`, + Short: "Delete an SSH key", + Long: `Allow you remove SSH Keys in a project. Remove a SSH Key from the project won't revoke the SSH Keys access for previously deploy and reinstall actions.`, RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_project_ssh_key_operation.go b/cli/get_project_ssh_key_operation.go index a223203..a977946 100755 --- a/cli/get_project_ssh_key_operation.go +++ b/cli/get_project_ssh_key_operation.go @@ -18,7 +18,8 @@ import ( func makeOperationSSHKeysGetProjectSSHKeyCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: `Returns a SSH Key in the project. These keys can be used to access servers after deploy and reinstall actions.`, + Short: "Retrieve an SSH key", + Long: `Returns a SSH Key in the project. These keys can be used to access servers after deploy and reinstall actions.`, RunE: runOperationSSHKeysGetProjectSSHKey, } diff --git a/cli/get_project_ssh_keys_operation.go b/cli/get_project_ssh_keys_operation.go index 76d9b45..b9a2903 100755 --- a/cli/get_project_ssh_keys_operation.go +++ b/cli/get_project_ssh_keys_operation.go @@ -16,7 +16,8 @@ import ( func makeOperationSSHKeysGetProjectSSHKeysCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `List all SSH Keys in the project. These keys can be used to access servers after deploy and reinstall actions.`, + Short: "List SSH keys", + Long: `List all SSH Keys in the project. These keys can be used to access servers after deploy and reinstall actions.`, RunE: runOperationSSHKeysGetProjectSSHKeys, } diff --git a/cli/post_project_ssh_key_operation.go b/cli/post_project_ssh_key_operation.go index 84d6240..927106a 100755 --- a/cli/post_project_ssh_key_operation.go +++ b/cli/post_project_ssh_key_operation.go @@ -27,7 +27,8 @@ type CreateSSHKeyOperation struct { func (o *CreateSSHKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: `Allow you create SSH Keys in a project. These keys can be used to access servers after deploy and reinstall actions.`, + Short: "Create an SSH key", + Long: `Allow you create SSH Keys in a project. These keys can be used to access servers after deploy and reinstall actions.`, RunE: o.run, PreRun: o.preRun, } diff --git a/cli/put_project_ssh_key_operation.go b/cli/put_project_ssh_key_operation.go index 75a5db0..3e14168 100755 --- a/cli/put_project_ssh_key_operation.go +++ b/cli/put_project_ssh_key_operation.go @@ -27,7 +27,8 @@ type UpdateSSHKeyOperation struct { func (o *UpdateSSHKeyOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: `Allow you update SSH Key in a project. These keys can be used to access servers after deploy and reinstall actions.`, + Short: "Update an SSH key", + Long: `Allow you update SSH Key in a project. These keys can be used to access servers after deploy and reinstall actions.`, RunE: o.run, PreRun: o.preRun, } From f498da6ee01125904cea0e1518ff8976973899e3 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:35:20 -0300 Subject: [PATCH 08/28] chore: adjustments to virtual_networks subcommands descriptions --- cli/create_virtual_network_operation.go | 2 +- cli/destroy_virtual_network_operation.go | 2 +- cli/get_virtual_network_operation.go | 2 +- cli/get_virtual_networks_operation.go | 2 +- cli/update_virtual_network_operation.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/create_virtual_network_operation.go b/cli/create_virtual_network_operation.go index 2a71f3b..c654dc3 100755 --- a/cli/create_virtual_network_operation.go +++ b/cli/create_virtual_network_operation.go @@ -27,7 +27,7 @@ type CreateVirtualNetworkOperation struct { func (o *CreateVirtualNetworkOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: "Creates a new Virtual Network.", + Short: "Creates a virtual network", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/destroy_virtual_network_operation.go b/cli/destroy_virtual_network_operation.go index 8c7bd30..c577050 100755 --- a/cli/destroy_virtual_network_operation.go +++ b/cli/destroy_virtual_network_operation.go @@ -26,7 +26,7 @@ func makeOperationVirtualNetworksDestroyVirtualNetworkCmd() (*cobra.Command, err func (o *DeleteVirtualNetworkOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: "Delete virtual network.", + Short: "Delete a virtual network", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_virtual_network_operation.go b/cli/get_virtual_network_operation.go index ebcf0d0..a0af843 100755 --- a/cli/get_virtual_network_operation.go +++ b/cli/get_virtual_network_operation.go @@ -18,7 +18,7 @@ import ( func makeOperationVirtualNetworksGetVirtualNetworkCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "get", - Short: `Retrieve a Virtual Network.`, + Short: "Retrieve a virtual network", RunE: runOperationVirtualNetworksGetVirtualNetwork, } diff --git a/cli/get_virtual_networks_operation.go b/cli/get_virtual_networks_operation.go index 5b12723..541ffcd 100755 --- a/cli/get_virtual_networks_operation.go +++ b/cli/get_virtual_networks_operation.go @@ -16,7 +16,7 @@ import ( func makeOperationVirtualNetworksGetVirtualNetworksCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Lists virtual networks assigned to a project.`, + Short: "List virtual networks", RunE: runOperationVirtualNetworksGetVirtualNetworks, } diff --git a/cli/update_virtual_network_operation.go b/cli/update_virtual_network_operation.go index 79904db..2d35291 100755 --- a/cli/update_virtual_network_operation.go +++ b/cli/update_virtual_network_operation.go @@ -27,7 +27,7 @@ type UpdateVirtualNetworkOperation struct { func (o *UpdateVirtualNetworkOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "update", - Short: "Update a Virtual Network.", + Short: "Update a virtual network", RunE: o.run, PreRun: o.preRun, } From 014caa7b174c7760d4c5e7dc188100601645fd9e Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Fri, 23 Feb 2024 18:39:52 -0300 Subject: [PATCH 09/28] chore: adjustments to vlan assignments subcommands descriptions --- cli/assign_server_virtual_network_operation.go | 2 +- cli/delete_virtual_networks_assignments_operation.go | 2 +- cli/get_virtual_networks_assignments_operation.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/assign_server_virtual_network_operation.go b/cli/assign_server_virtual_network_operation.go index da71c69..8244c9a 100755 --- a/cli/assign_server_virtual_network_operation.go +++ b/cli/assign_server_virtual_network_operation.go @@ -26,7 +26,7 @@ type CreateVirtualNetworkAssignmentOperation struct { func (o *CreateVirtualNetworkAssignmentOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "create", - Short: "Assign a server to a virtual network.", + Short: "Assign a server to a virtual network", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/delete_virtual_networks_assignments_operation.go b/cli/delete_virtual_networks_assignments_operation.go index 9cee3b4..a9b5cca 100755 --- a/cli/delete_virtual_networks_assignments_operation.go +++ b/cli/delete_virtual_networks_assignments_operation.go @@ -26,7 +26,7 @@ type DeleteVirtualNetworkAssignmentOperation struct { func (o *DeleteVirtualNetworkAssignmentOperation) Register() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "destroy", - Short: "Allow you to remove a Virtual Network assignment.", + Short: "Unassign a server from a virtual network", RunE: o.run, PreRun: o.preRun, } diff --git a/cli/get_virtual_networks_assignments_operation.go b/cli/get_virtual_networks_assignments_operation.go index 20019a9..fee929d 100755 --- a/cli/get_virtual_networks_assignments_operation.go +++ b/cli/get_virtual_networks_assignments_operation.go @@ -16,7 +16,8 @@ import ( func makeOperationVirtualNetworkAssignmentsGetVirtualNetworksAssignmentsCmd() (*cobra.Command, error) { cmd := &cobra.Command{ Use: "list", - Short: `Returns a list of all servers assigned to virtual networks.`, + Short: "List assignments", + Long: `Returns a list of all servers assigned to virtual networks.`, RunE: runOperationVirtualNetworkAssignmentsGetVirtualNetworksAssignments, } From 4407424f739d505c0d1665eeff55c0a0ee286768 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Tue, 27 Feb 2024 15:37:24 -0300 Subject: [PATCH 10/28] chore: remove unused and deprecated functions --- cli/autocomplete.go | 2 +- cli/get_plans_operation.go | 47 -------------- cli/get_project_operation.go | 71 --------------------- cli/get_project_ssh_key_operation.go | 71 --------------------- cli/get_virtual_network_operation.go | 71 --------------------- client/projects/update_project_responses.go | 12 ---- internal/prompt/prompt_number.go | 2 +- 7 files changed, 2 insertions(+), 274 deletions(-) diff --git a/cli/autocomplete.go b/cli/autocomplete.go index 9b6fa25..9285f7e 100755 --- a/cli/autocomplete.go +++ b/cli/autocomplete.go @@ -57,7 +57,7 @@ PowerShell: `, DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { switch args[0] { case "bash": diff --git a/cli/get_plans_operation.go b/cli/get_plans_operation.go index a9b2561..c88ad57 100755 --- a/cli/get_plans_operation.go +++ b/cli/get_plans_operation.go @@ -587,50 +587,3 @@ func retrieveOperationPlansGetPlansFilterStockLevelFlag(m *plans.GetPlansParams, } return nil, retAdded } - -// register flags to command -func registerModelGetPlansOKBodyFlags(depth int, cmdPrefix string, cmd *cobra.Command) error { - - if err := registerGetPlansOKBodyData(depth, cmdPrefix, cmd); err != nil { - return err - } - - return nil -} - -func registerGetPlansOKBodyData(depth int, cmdPrefix string, cmd *cobra.Command) error { - if depth > maxDepth { - return nil - } - - // warning: data []*models.PlanData array type is not supported by go-swagger cli yet - - return nil -} - -// retrieve flags from commands, and set value in model. Return true if any flag is passed by user to fill model field. -func retrieveModelGetPlansOKBodyFlags(depth int, m *plans.GetPlansOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - retAdded := false - - err, dataAdded := retrieveGetPlansOKBodyDataFlags(depth, m, cmdPrefix, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - - return nil, retAdded -} - -func retrieveGetPlansOKBodyDataFlags(depth int, m *plans.GetPlansOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - if depth > maxDepth { - return nil, false - } - retAdded := false - - dataFlagName := fmt.Sprintf("%v.data", cmdPrefix) - if cmd.Flags().Changed(dataFlagName) { - // warning: data array type []*models.PlanData is not supported by go-swagger cli yet - } - - return nil, retAdded -} diff --git a/cli/get_project_operation.go b/cli/get_project_operation.go index 5f15b00..531f7c8 100755 --- a/cli/get_project_operation.go +++ b/cli/get_project_operation.go @@ -8,9 +8,7 @@ import ( "github.com/latitudesh/lsh/client/projects" "github.com/latitudesh/lsh/internal/utils" - "github.com/latitudesh/lsh/models" - "github.com/go-openapi/swag" "github.com/spf13/cobra" ) @@ -148,72 +146,3 @@ func retrieveOperationProjectsGetProjectIDOrSlugFlag(m *projects.GetProjectParam } return nil, retAdded } - -// register flags to command -func registerModelGetProjectOKBodyFlags(depth int, cmdPrefix string, cmd *cobra.Command) error { - - if err := registerGetProjectOKBodyData(depth, cmdPrefix, cmd); err != nil { - return err - } - - return nil -} - -func registerGetProjectOKBodyData(depth int, cmdPrefix string, cmd *cobra.Command) error { - if depth > maxDepth { - return nil - } - - var dataFlagName string - if cmdPrefix == "" { - dataFlagName = "data" - } else { - dataFlagName = fmt.Sprintf("%v.data", cmdPrefix) - } - - if err := registerModelProjectFlags(depth+1, dataFlagName, cmd); err != nil { - return err - } - - return nil -} - -// retrieve flags from commands, and set value in model. Return true if any flag is passed by user to fill model field. -func retrieveModelGetProjectOKBodyFlags(depth int, m *projects.GetProjectOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - retAdded := false - - err, dataAdded := retrieveGetProjectOKBodyDataFlags(depth, m, cmdPrefix, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - - return nil, retAdded -} - -func retrieveGetProjectOKBodyDataFlags(depth int, m *projects.GetProjectOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - if depth > maxDepth { - return nil, false - } - retAdded := false - - dataFlagName := fmt.Sprintf("%v.data", cmdPrefix) - if cmd.Flags().Changed(dataFlagName) { - // info: complex object data models.Project is retrieved outside this Changed() block - } - dataFlagValue := m.Data - if swag.IsZero(dataFlagValue) { - dataFlagValue = &models.Project{} - } - - err, dataAdded := retrieveModelProjectFlags(depth+1, dataFlagValue, dataFlagName, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - if dataAdded { - m.Data = dataFlagValue - } - - return nil, retAdded -} diff --git a/cli/get_project_ssh_key_operation.go b/cli/get_project_ssh_key_operation.go index a223203..a897206 100755 --- a/cli/get_project_ssh_key_operation.go +++ b/cli/get_project_ssh_key_operation.go @@ -8,9 +8,7 @@ import ( "github.com/latitudesh/lsh/client/ssh_keys" "github.com/latitudesh/lsh/internal/utils" - "github.com/latitudesh/lsh/models" - "github.com/go-openapi/swag" "github.com/spf13/cobra" ) @@ -149,72 +147,3 @@ func retrieveOperationSSHKeysGetProjectSSHKeySSHKeyIDFlag(m *ssh_keys.GetProject } return nil, retAdded } - -// register flags to command -func registerModelGetProjectSSHKeyOKBodyFlags(depth int, cmdPrefix string, cmd *cobra.Command) error { - - if err := registerGetProjectSSHKeyOKBodyData(depth, cmdPrefix, cmd); err != nil { - return err - } - - return nil -} - -func registerGetProjectSSHKeyOKBodyData(depth int, cmdPrefix string, cmd *cobra.Command) error { - if depth > maxDepth { - return nil - } - - var dataFlagName string - if cmdPrefix == "" { - dataFlagName = "data" - } else { - dataFlagName = fmt.Sprintf("%v.data", cmdPrefix) - } - - if err := registerModelSSHKeyDataFlags(depth+1, dataFlagName, cmd); err != nil { - return err - } - - return nil -} - -// retrieve flags from commands, and set value in model. Return true if any flag is passed by user to fill model field. -func retrieveModelGetProjectSSHKeyOKBodyFlags(depth int, m *ssh_keys.GetProjectSSHKeyOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - retAdded := false - - err, dataAdded := retrieveGetProjectSSHKeyOKBodyDataFlags(depth, m, cmdPrefix, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - - return nil, retAdded -} - -func retrieveGetProjectSSHKeyOKBodyDataFlags(depth int, m *ssh_keys.GetProjectSSHKeyOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - if depth > maxDepth { - return nil, false - } - retAdded := false - - dataFlagName := fmt.Sprintf("%v.data", cmdPrefix) - if cmd.Flags().Changed(dataFlagName) { - // info: complex object data models.SSHKeyData is retrieved outside this Changed() block - } - dataFlagValue := m.Data - if swag.IsZero(dataFlagValue) { - dataFlagValue = &models.SSHKeyData{} - } - - err, dataAdded := retrieveModelSSHKeyDataFlags(depth+1, dataFlagValue, dataFlagName, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - if dataAdded { - m.Data = dataFlagValue - } - - return nil, retAdded -} diff --git a/cli/get_virtual_network_operation.go b/cli/get_virtual_network_operation.go index ebcf0d0..b07ee6d 100755 --- a/cli/get_virtual_network_operation.go +++ b/cli/get_virtual_network_operation.go @@ -8,9 +8,7 @@ import ( "github.com/latitudesh/lsh/client/virtual_networks" "github.com/latitudesh/lsh/internal/utils" - "github.com/latitudesh/lsh/models" - "github.com/go-openapi/swag" "github.com/spf13/cobra" ) @@ -105,72 +103,3 @@ func retrieveOperationVirtualNetworksGetVirtualNetworkIDFlag(m *virtual_networks } return nil, retAdded } - -// register flags to command -func registerModelGetVirtualNetworkOKBodyFlags(depth int, cmdPrefix string, cmd *cobra.Command) error { - - if err := registerGetVirtualNetworkOKBodyData(depth, cmdPrefix, cmd); err != nil { - return err - } - - return nil -} - -func registerGetVirtualNetworkOKBodyData(depth int, cmdPrefix string, cmd *cobra.Command) error { - if depth > maxDepth { - return nil - } - - var dataFlagName string - if cmdPrefix == "" { - dataFlagName = "data" - } else { - dataFlagName = fmt.Sprintf("%v.data", cmdPrefix) - } - - if err := registerModelVirtualNetworkFlags(depth+1, dataFlagName, cmd); err != nil { - return err - } - - return nil -} - -// retrieve flags from commands, and set value in model. Return true if any flag is passed by user to fill model field. -func retrieveModelGetVirtualNetworkOKBodyFlags(depth int, m *virtual_networks.GetVirtualNetworkOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - retAdded := false - - err, dataAdded := retrieveGetVirtualNetworkOKBodyDataFlags(depth, m, cmdPrefix, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - - return nil, retAdded -} - -func retrieveGetVirtualNetworkOKBodyDataFlags(depth int, m *virtual_networks.GetVirtualNetworkOKBody, cmdPrefix string, cmd *cobra.Command) (error, bool) { - if depth > maxDepth { - return nil, false - } - retAdded := false - - dataFlagName := fmt.Sprintf("%v.data", cmdPrefix) - if cmd.Flags().Changed(dataFlagName) { - // info: complex object data models.VirtualNetwork is retrieved outside this Changed() block - } - dataFlagValue := m.Data - if swag.IsZero(dataFlagValue) { - dataFlagValue = &models.VirtualNetwork{} - } - - err, dataAdded := retrieveModelVirtualNetworkFlags(depth+1, dataFlagValue, dataFlagName, cmd) - if err != nil { - return err, false - } - retAdded = retAdded || dataAdded - if dataAdded { - m.Data = dataFlagValue - } - - return nil, retAdded -} diff --git a/client/projects/update_project_responses.go b/client/projects/update_project_responses.go index 8f17834..bb9d1a7 100755 --- a/client/projects/update_project_responses.go +++ b/client/projects/update_project_responses.go @@ -188,18 +188,6 @@ func (o *UpdateProjectForbidden) GetPayload() *models.ErrorObject { return o.Payload } -func (o *UpdateProjectForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - o.Payload = new(models.ErrorObject) - - // response payload - if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { - return err - } - - return nil -} - /* UpdateProjectBody update project body swagger:model UpdateProjectBody diff --git a/internal/prompt/prompt_number.go b/internal/prompt/prompt_number.go index 8c2c8d6..95a2dfd 100644 --- a/internal/prompt/prompt_number.go +++ b/internal/prompt/prompt_number.go @@ -65,7 +65,7 @@ func valueAsNumber(value string) (int64, error) { numberValue, err := strconv.ParseInt(value, 10, 64) if err != nil { - return 0, errors.New("Invalid number") + return 0, errors.New("invalid number") } return numberValue, nil From 288eaeb2847df5ee8c6c58ed32014205a699cbef Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Tue, 27 Feb 2024 15:39:25 -0300 Subject: [PATCH 11/28] chore: apply gofmt --- client/api_keys/get_api_keys_parameters.go | 1 - client/servers/get_servers_parameters.go | 1 - client/virtual_networks/virtual_networks_client.go | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/client/api_keys/get_api_keys_parameters.go b/client/api_keys/get_api_keys_parameters.go index 2bc771c..b96811f 100755 --- a/client/api_keys/get_api_keys_parameters.go +++ b/client/api_keys/get_api_keys_parameters.go @@ -60,7 +60,6 @@ GetAPIKeysParams contains all the parameters to send to the API endpoint Typically these are written to a http.Request. */ type GetAPIKeysParams struct { - timeout time.Duration Context context.Context HTTPClient *http.Client diff --git a/client/servers/get_servers_parameters.go b/client/servers/get_servers_parameters.go index c87fd33..fd8450b 100755 --- a/client/servers/get_servers_parameters.go +++ b/client/servers/get_servers_parameters.go @@ -157,7 +157,6 @@ type GetServersParams struct { */ FilterStatus *string - timeout time.Duration Context context.Context HTTPClient *http.Client diff --git a/client/virtual_networks/virtual_networks_client.go b/client/virtual_networks/virtual_networks_client.go index 2f8fe80..2c75569 100755 --- a/client/virtual_networks/virtual_networks_client.go +++ b/client/virtual_networks/virtual_networks_client.go @@ -14,7 +14,7 @@ import ( var ( createvirtualNetworkType = "virtual_network" - updatevirtualNetworkType = "virtual_networks" + updatevirtualNetworkType = "virtual_networks" ) // New creates a new virtual networks API client. From 49818331bb95601c7342bbe6cd8178566d8888f1 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Wed, 27 Mar 2024 19:17:03 -0300 Subject: [PATCH 12/28] feat: add doc generator --- go.mod | 4 +- go.sum | 2 + internal/generator/documentation/generate.go | 110 +++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 internal/generator/documentation/generate.go diff --git a/go.mod b/go.mod index b809af0..fb9daa2 100755 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.8.0 + github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 golang.org/x/text v0.14.0 ) @@ -19,6 +20,7 @@ require ( require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -39,12 +41,12 @@ require ( github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.mongodb.org/mongo-driver v1.13.1 // indirect go.opentelemetry.io/otel v1.17.0 // indirect diff --git a/go.sum b/go.sum index 143a1af..bac783d 100755 --- a/go.sum +++ b/go.sum @@ -6,6 +6,7 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5O github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -87,6 +88,7 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go new file mode 100644 index 0000000..1a006a4 --- /dev/null +++ b/internal/generator/documentation/generate.go @@ -0,0 +1,110 @@ +package main + +import ( + "fmt" + "log" + "os" + "strings" + + "github.com/latitudesh/lsh/cli" + "github.com/spf13/cobra" +) + +const IGNORED = 0 +const GENERAL = 1 + +// Map to Control the output +var cmdSelection = map[string]int{ + "completion": 0, + "update": 1, + "login": 1, +} + +func main() { + rootCmd, err := cli.MakeRootCmd() + if err != nil { + log.Fatal("Cmd construction error: ", err) + os.Exit(1) + } + + f, err := os.Create("commands.md") + if err != nil { + log.Fatal(err) + } + defer f.Close() + + generalCmds := []*cobra.Command{} + lshCmds := []*cobra.Command{} + + for _, c := range rootCmd.Commands() { + value, ok := cmdSelection[c.Name()] + if ok { + if value == IGNORED { + continue + } + if value == GENERAL { + generalCmds = append(generalCmds, c) + continue + } + } + lshCmds = append(lshCmds, c) + } + + // If command is a general command + if len(generalCmds) != 0 { + generalSection := buildGeneral(generalCmds) + f.WriteString(generalSection) + } + + // If command is a normal CLI command + if len(lshCmds) != 0 { + for _, cmd := range lshCmds { + cmdSection := buildSection(cmd) + f.WriteString(cmdSection) + } + } +} + +func buildSection(cmd *cobra.Command) string { + var section strings.Builder + header := fmt.Sprintf("## %s\n", cmd.Name()) + section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) + + subCmdString := "" + for _, subCmd := range cmd.Commands() { + // Verify if command has sub-commands + if len(subCmd.Commands()) != 0 { + subCmdString = buildSubSection(subCmd) + continue + } + + section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s\n```\n", cmd.Name(), subCmd.Name())) + } + section.WriteString(subCmdString) + + return section.String() +} + +func buildSubSection(cmd *cobra.Command) string { + var section strings.Builder + header := fmt.Sprintf("## %s %s\n", cmd.Parent().Name(), cmd.Name()) + section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) + + for _, subCmd := range cmd.Commands() { + section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s %s\n```\n", cmd.Name(), cmd.Parent().Name(), subCmd.Name())) + } + return section.String() +} + +func buildGeneral(cmds []*cobra.Command) string { + var section strings.Builder + header := "## General\n" + section.WriteString(header) + for _, cmd := range cmds { + section.WriteString(fmt.Sprintf("**%s**\n", cmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s\n```\n", cmd.Name())) + } + return section.String() +} From 4ec2820c4cf58965e029c6551d41a0e50ad021be Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Wed, 27 Mar 2024 19:20:26 -0300 Subject: [PATCH 13/28] chore: remove old doc generator --- internal/docs/cmd_page.go | 45 --------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 internal/docs/cmd_page.go diff --git a/internal/docs/cmd_page.go b/internal/docs/cmd_page.go deleted file mode 100644 index ee460dc..0000000 --- a/internal/docs/cmd_page.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - "strings" - - "github.com/latitudesh/lsh/cli" - "github.com/spf13/cobra" -) - -const Ignored = 0 -const General = 1 - -func main() { - f, err := os.Create("commands.md") - if err != nil { - log.Fatal(err) - } - defer f.Close() - - rootCmd, err := cli.MakeRootCmd() - if err != nil { - log.Fatal("Cmd construction error: ", err) - os.Exit(1) - } - - for _, c := range rootCmd.Commands() { - cmdSection := buildSection(c) - f.WriteString(cmdSection) - } -} - -func buildSection(cmd *cobra.Command) string { - var section strings.Builder - header := fmt.Sprintf("## %s\n", cmd.Name()) - section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) - - for _, subCmd := range cmd.Commands() { - section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) - section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s\n```\n", cmd.Name(), subCmd.Name())) - } - return section.String() -} From c4cc12e4cbd492dc00ec256f13641620d0e411a5 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Wed, 27 Mar 2024 21:18:27 -0300 Subject: [PATCH 14/28] feat: add help section --- internal/generator/documentation/generate.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go index 1a006a4..35aeb8a 100644 --- a/internal/generator/documentation/generate.go +++ b/internal/generator/documentation/generate.go @@ -8,12 +8,16 @@ import ( "github.com/latitudesh/lsh/cli" "github.com/spf13/cobra" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) const IGNORED = 0 const GENERAL = 1 -// Map to Control the output +var caser = cases.Title(language.English) + +// cmdSelections to customize the output var cmdSelection = map[string]int{ "completion": 0, "update": 1, @@ -63,12 +67,15 @@ func main() { f.WriteString(cmdSection) } } + + // Help section + f.WriteString(buildHelp()) } func buildSection(cmd *cobra.Command) string { var section strings.Builder header := fmt.Sprintf("## %s\n", cmd.Name()) - section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) + section.WriteString(caser.String(strings.Replace(header, "_", " ", 1))) subCmdString := "" for _, subCmd := range cmd.Commands() { @@ -89,7 +96,7 @@ func buildSection(cmd *cobra.Command) string { func buildSubSection(cmd *cobra.Command) string { var section strings.Builder header := fmt.Sprintf("## %s %s\n", cmd.Parent().Name(), cmd.Name()) - section.WriteString(strings.Title(strings.Replace(header, "_", " ", 1))) + section.WriteString(caser.String(strings.Replace(header, "_", " ", 1))) for _, subCmd := range cmd.Commands() { section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) @@ -108,3 +115,9 @@ func buildGeneral(cmds []*cobra.Command) string { } return section.String() } + +func buildHelp() string { + return `## Help +- Use lsh -h to get a list of all available commands +- To see how to use a command, use lsh -h` +} From 5ffc88bc34626dc718917098ff1778c041c9d142 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 14:27:48 -0300 Subject: [PATCH 15/28] feat: add ghaction to sync docs --- .github/workflows/release.yml | 21 ++++++++++++++++++++ internal/generator/documentation/generate.go | 20 +++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2f6f2f..568e678 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,3 +34,24 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }} + + generate-docs: + steps: + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21.6' + - + name: Generate documentation + run: go run internal/generator/documentation/generate.go + - + name: Sync to readme + run: | + docs=$( jq -sR '{"body": .}' commands.md ) + curl --request PUT \ + --url https://dash.readme.com/api/v1/docs/cli-commands \ + --header 'accept: application/json' \ + --header 'authorization: Basic ${{ secrets.README_API_KEY }}' \ + --header 'content-type: application/json' \ + --data $docs diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go index 35aeb8a..845924a 100644 --- a/internal/generator/documentation/generate.go +++ b/internal/generator/documentation/generate.go @@ -74,7 +74,7 @@ func main() { func buildSection(cmd *cobra.Command) string { var section strings.Builder - header := fmt.Sprintf("## %s\n", cmd.Name()) + header := fmt.Sprintf("## %s\n\n", cmd.Name()) section.WriteString(caser.String(strings.Replace(header, "_", " ", 1))) subCmdString := "" @@ -85,8 +85,8 @@ func buildSection(cmd *cobra.Command) string { continue } - section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) - section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s\n```\n", cmd.Name(), subCmd.Name())) + section.WriteString(fmt.Sprintf("**%s**\n\n", subCmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s\n```\n\n", cmd.Name(), subCmd.Name())) } section.WriteString(subCmdString) @@ -95,29 +95,29 @@ func buildSection(cmd *cobra.Command) string { func buildSubSection(cmd *cobra.Command) string { var section strings.Builder - header := fmt.Sprintf("## %s %s\n", cmd.Parent().Name(), cmd.Name()) + header := fmt.Sprintf("## %s %s\n\n", cmd.Parent().Name(), cmd.Name()) section.WriteString(caser.String(strings.Replace(header, "_", " ", 1))) for _, subCmd := range cmd.Commands() { - section.WriteString(fmt.Sprintf("**%s**\n", subCmd.Short)) - section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s %s\n```\n", cmd.Name(), cmd.Parent().Name(), subCmd.Name())) + section.WriteString(fmt.Sprintf("**%s**\n\n", subCmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s %s %s\n```\n\n", cmd.Name(), cmd.Parent().Name(), subCmd.Name())) } return section.String() } func buildGeneral(cmds []*cobra.Command) string { var section strings.Builder - header := "## General\n" + header := "## General\n\n" section.WriteString(header) for _, cmd := range cmds { - section.WriteString(fmt.Sprintf("**%s**\n", cmd.Short)) - section.WriteString(fmt.Sprintf("```Shell\nlsh %s\n```\n", cmd.Name())) + section.WriteString(fmt.Sprintf("**%s**\n\n", cmd.Short)) + section.WriteString(fmt.Sprintf("```Shell\nlsh %s\n```\n\n", cmd.Name())) } return section.String() } func buildHelp() string { - return `## Help + return `### Help - Use lsh -h to get a list of all available commands - To see how to use a command, use lsh -h` } From 676bf95b4ad80222d6dbacc75cff4de731d9fe87 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 14:31:03 -0300 Subject: [PATCH 16/28] chore: gitignore commands.md to keep git state clean --- .gitignore | 1 + internal/generator/documentation/generate.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cde0123..59c1301 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist/ +commands.md \ No newline at end of file diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go index 845924a..48cd4eb 100644 --- a/internal/generator/documentation/generate.go +++ b/internal/generator/documentation/generate.go @@ -19,9 +19,9 @@ var caser = cases.Title(language.English) // cmdSelections to customize the output var cmdSelection = map[string]int{ - "completion": 0, - "update": 1, - "login": 1, + "completion": IGNORED, + "update": GENERAL, + "login": GENERAL, } func main() { From 1889bd544c63fbf57ce4235b85ed42a1b9d48205 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 14:49:42 -0300 Subject: [PATCH 17/28] chore: small changes to doc generator --- internal/generator/documentation/generate.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go index 48cd4eb..57c41b9 100644 --- a/internal/generator/documentation/generate.go +++ b/internal/generator/documentation/generate.go @@ -28,7 +28,6 @@ func main() { rootCmd, err := cli.MakeRootCmd() if err != nil { log.Fatal("Cmd construction error: ", err) - os.Exit(1) } f, err := os.Create("commands.md") @@ -40,18 +39,18 @@ func main() { generalCmds := []*cobra.Command{} lshCmds := []*cobra.Command{} - for _, c := range rootCmd.Commands() { - value, ok := cmdSelection[c.Name()] + for _, cmd := range rootCmd.Commands() { + value, ok := cmdSelection[cmd.Name()] if ok { if value == IGNORED { continue } if value == GENERAL { - generalCmds = append(generalCmds, c) + generalCmds = append(generalCmds, cmd) continue } } - lshCmds = append(lshCmds, c) + lshCmds = append(lshCmds, cmd) } // If command is a general command From 33692e51052264ed1cd6529003ca603fc2640324 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 14:59:30 -0300 Subject: [PATCH 18/28] fix: release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 568e678..1c99174 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ permissions: jobs: - goreleaser: + goreleaser: runs-on: ubuntu-latest steps: - From 0689e4af633a69f51a20f87a07324a40acad6c61 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 20:08:34 -0300 Subject: [PATCH 19/28] feat: Add tags to servers model --- models/server_data.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/models/server_data.go b/models/server_data.go index e832bd8..7a6f230 100755 --- a/models/server_data.go +++ b/models/server_data.go @@ -123,6 +123,10 @@ func (m *ServerData) TableRow() table.Row { Label: "ID", Value: table.String(m.ID), }, + "tags": table.Cell{ + Label: "Tags", + Value: table.StringList(tags(attr), ","), + }, "hostname": table.Cell{ Label: "Hostname", Value: table.String(attr.Hostname), @@ -200,10 +204,21 @@ func plan(attributes *ServerDataAttributes) string { return "" } +func tags(attributes *ServerDataAttributes) []string { + name := []string{} + tags := attributes.Tags + + for _, tag := range tags { + name = append(name, tag.Name) + } + return name +} + // ServerDataAttributes server data attributes // // swagger:model ServerDataAttributes type ServerDataAttributes struct { + Tags []*ServerDataAttributesTags `json:"tags,omitempty"` // created at CreatedAt *string `json:"created_at,omitempty"` @@ -697,6 +712,13 @@ func (m *ServerDataAttributes) UnmarshalBinary(b []byte) error { return nil } +type ServerDataAttributesTags struct { + Id string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Color string `json:"color,omitempty"` +} + // ServerDataAttributesOperatingSystem server data attributes operating system // // swagger:model ServerDataAttributesOperatingSystem From 4b64581853fceed06331065bdc435996ea4da7b1 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Thu, 28 Mar 2024 21:30:28 -0300 Subject: [PATCH 20/28] feat: add server tags update --- cli/update_server_operation.go | 6 ++++++ client/servers/update_server_responses.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/cli/update_server_operation.go b/cli/update_server_operation.go index d67326e..0ca834f 100755 --- a/cli/update_server_operation.go +++ b/cli/update_server_operation.go @@ -70,6 +70,12 @@ func (o *UpdateServerOperation) registerFlags(cmd *cobra.Command) { Options: server.SupportedBillingTypes, Required: false, }, + &cmdflag.StringSlice{ + Name: "tags", + Label: "Tags", + Description: "Tags", + Required: false, + }, } o.PathParamFlags.Register(pathParamsSchema) diff --git a/client/servers/update_server_responses.go b/client/servers/update_server_responses.go index 8509a41..10d3e44 100755 --- a/client/servers/update_server_responses.go +++ b/client/servers/update_server_responses.go @@ -298,6 +298,8 @@ type UpdateServerParamsBodyAttributes struct { // hostname Hostname string `json:"hostname,omitempty"` + + Tags []string `json:"tags,omitempty"` } // Validate validates this update server params body attributes From 649dcde581ca814a3a0f47f9e2c1a7bcfd88b122 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Sun, 31 Mar 2024 13:26:35 -0300 Subject: [PATCH 21/28] feat: Add filter by tag to servers list --- cli/get_servers_operation.go | 44 ++++++++++++++++++++++++ client/servers/get_servers_parameters.go | 27 +++++++++++++++ models/server_data.go | 15 ++------ models/tags.go | 8 +++++ 4 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 models/tags.go diff --git a/cli/get_servers_operation.go b/cli/get_servers_operation.go index 2ce76a4..287ba65 100755 --- a/cli/get_servers_operation.go +++ b/cli/get_servers_operation.go @@ -86,6 +86,9 @@ func runOperationServersGetServers(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationServersGetServersFilterStatusFlag(params, "", cmd); err != nil { return err } + if err, _ := retrieveOperationServersGetServersFilterTagsFlag(params, "", cmd); err != nil { + return err + } if dryRun { logDebugf("dry-run flag specified. Skip sending request.") @@ -157,6 +160,10 @@ func registerOperationServersGetServersParamFlags(cmd *cobra.Command) error { if err := registerOperationServersGetServersFilterStatusParamFlags("", cmd); err != nil { return err } + if err := registerOperationServersGetServersFilterTagsParamFlags("", cmd); err != nil { + return err + } + return nil } @@ -449,6 +456,23 @@ func registerOperationServersGetServersFilterStatusParamFlags(cmdPrefix string, return nil } +func registerOperationServersGetServersFilterTagsParamFlags(cmdPrefix string, cmd *cobra.Command) error { + + filterTagsDescription := `The Tags to filter by` + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + var filterTagsFlagDefault = "" + + _ = cmd.PersistentFlags().String(filterTagsFlagName, filterTagsFlagDefault, filterTagsDescription) + + return nil +} func retrieveOperationServersGetServersExtraFieldsServersFlag(m *servers.GetServersParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { retAdded := false @@ -790,3 +814,23 @@ func retrieveOperationServersGetServersFilterStatusFlag(m *servers.GetServersPar } return nil, retAdded } +func retrieveOperationServersGetServersFilterTagsFlag(m *servers.GetServersParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { + retAdded := false + if cmd.Flags().Changed("tags") { + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + filterTagsFlagValue, err := cmd.Flags().GetString(filterTagsFlagName) + if err != nil { + return err, false + } + m.FilterTags = &filterTagsFlagValue + + } + return nil, retAdded +} diff --git a/client/servers/get_servers_parameters.go b/client/servers/get_servers_parameters.go index fd8450b..bdeab32 100755 --- a/client/servers/get_servers_parameters.go +++ b/client/servers/get_servers_parameters.go @@ -157,6 +157,8 @@ type GetServersParams struct { */ FilterStatus *string + FilterTags *string + timeout time.Duration Context context.Context HTTPClient *http.Client @@ -402,6 +404,15 @@ func (o *GetServersParams) SetFilterStatus(filterStatus *string) { o.FilterStatus = filterStatus } +func (o *GetServersParams) WithFilterTags(filterTags *string) *GetServersParams { + o.SetFilterTags(filterTags) + return o +} + +func (o *GetServersParams) SetFilterTags(filterTags *string) { + o.FilterTags = filterTags +} + // WriteToRequest writes these params to a swagger request func (o *GetServersParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -703,6 +714,22 @@ func (o *GetServersParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Re } } + if o.FilterTags != nil { + + var qrFilterTags string + + if o.FilterTags != nil { + qrFilterTags = *o.FilterTags + } + qFilterTags := qrFilterTags + if qFilterTags != "" { + + if err := r.SetQueryParam("filter[tags]", qFilterTags); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/models/server_data.go b/models/server_data.go index 7a6f230..d30a542 100755 --- a/models/server_data.go +++ b/models/server_data.go @@ -125,7 +125,7 @@ func (m *ServerData) TableRow() table.Row { }, "tags": table.Cell{ Label: "Tags", - Value: table.StringList(tags(attr), ","), + Value: table.StringList(tags(attr.Tags), ","), }, "hostname": table.Cell{ Label: "Hostname", @@ -204,10 +204,8 @@ func plan(attributes *ServerDataAttributes) string { return "" } -func tags(attributes *ServerDataAttributes) []string { +func tags(tags []*TagsIncude) []string { name := []string{} - tags := attributes.Tags - for _, tag := range tags { name = append(name, tag.Name) } @@ -218,7 +216,7 @@ func tags(attributes *ServerDataAttributes) []string { // // swagger:model ServerDataAttributes type ServerDataAttributes struct { - Tags []*ServerDataAttributesTags `json:"tags,omitempty"` + Tags []*TagsIncude `json:"tags,omitempty"` // created at CreatedAt *string `json:"created_at,omitempty"` @@ -712,13 +710,6 @@ func (m *ServerDataAttributes) UnmarshalBinary(b []byte) error { return nil } -type ServerDataAttributesTags struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Color string `json:"color,omitempty"` -} - // ServerDataAttributesOperatingSystem server data attributes operating system // // swagger:model ServerDataAttributesOperatingSystem diff --git a/models/tags.go b/models/tags.go new file mode 100644 index 0000000..81e6163 --- /dev/null +++ b/models/tags.go @@ -0,0 +1,8 @@ +package models + +type TagsIncude struct { + Id string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Color string `json:"color,omitempty"` +} From 0bb175af9ce625b922a981867205af28d726fac2 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Sun, 31 Mar 2024 13:53:53 -0300 Subject: [PATCH 22/28] feat: Add tags to ssh_keys --- cli/get_project_ssh_keys_operation.go | 45 +++++++++++++++++++ cli/put_project_ssh_key_operation.go | 6 +++ .../get_project_ssh_keys_parameters.go | 27 +++++++++++ .../ssh_keys/put_project_ssh_key_responses.go | 2 + models/ssh_key_data.go | 6 ++- 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/cli/get_project_ssh_keys_operation.go b/cli/get_project_ssh_keys_operation.go index 76d9b45..0da30a6 100755 --- a/cli/get_project_ssh_keys_operation.go +++ b/cli/get_project_ssh_keys_operation.go @@ -38,6 +38,9 @@ func runOperationSSHKeysGetProjectSSHKeys(cmd *cobra.Command, args []string) err if err, _ := retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(params, "", cmd); err != nil { return err } + if err, _ := retrieveOperationSSHKeysFilterTagsFlag(params, "", cmd); err != nil { + return err + } if dryRun { logDebugf("dry-run flag specified. Skip sending request.") @@ -61,6 +64,9 @@ func registerOperationSSHKeysGetProjectSSHKeysParamFlags(cmd *cobra.Command) err if err := registerOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugParamFlags("", cmd); err != nil { return err } + if err := registerOperationSSHKeysFilterTagsFlag("", cmd); err != nil { + return err + } return nil } @@ -83,6 +89,24 @@ func registerOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugParamFlags(cmdPrefi return nil } +func registerOperationSSHKeysFilterTagsFlag(cmdPrefix string, cmd *cobra.Command) error { + + filterTagsDescription := `The Tags to filter by` + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + var filterTagsFlagDefault = "" + + _ = cmd.PersistentFlags().String(filterTagsFlagName, filterTagsFlagDefault, filterTagsDescription) + + return nil +} + func retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(m *ssh_keys.GetProjectSSHKeysParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { retAdded := false if cmd.Flags().Changed("project") { @@ -103,3 +127,24 @@ func retrieveOperationSSHKeysGetProjectSSHKeysProjectIDOrSlugFlag(m *ssh_keys.Ge } return nil, retAdded } + +func retrieveOperationSSHKeysFilterTagsFlag(m *ssh_keys.GetProjectSSHKeysParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { + retAdded := false + if cmd.Flags().Changed("tags") { + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + filterTagsFlagValue, err := cmd.Flags().GetString(filterTagsFlagName) + if err != nil { + return err, false + } + m.FilterTags = &filterTagsFlagValue + + } + return nil, retAdded +} diff --git a/cli/put_project_ssh_key_operation.go b/cli/put_project_ssh_key_operation.go index 75a5db0..0d85422 100755 --- a/cli/put_project_ssh_key_operation.go +++ b/cli/put_project_ssh_key_operation.go @@ -63,6 +63,12 @@ func (o *UpdateSSHKeyOperation) registerFlags(cmd *cobra.Command) { Description: "Name of the SSH Key", Required: true, }, + &cmdflag.StringSlice{ + Name: "tags", + Label: "Tags", + Description: "Tags", + Required: false, + }, } o.PathParamFlags.Register(pathParamsSchema) diff --git a/client/ssh_keys/get_project_ssh_keys_parameters.go b/client/ssh_keys/get_project_ssh_keys_parameters.go index 81ee964..6d877be 100755 --- a/client/ssh_keys/get_project_ssh_keys_parameters.go +++ b/client/ssh_keys/get_project_ssh_keys_parameters.go @@ -64,6 +64,8 @@ type GetProjectSSHKeysParams struct { // ProjectIDOrSlug. ProjectIDOrSlug string + FilterTags *string + timeout time.Duration Context context.Context HTTPClient *http.Client @@ -133,6 +135,15 @@ func (o *GetProjectSSHKeysParams) SetProjectIDOrSlug(projectIDOrSlug string) { o.ProjectIDOrSlug = projectIDOrSlug } +func (o *GetProjectSSHKeysParams) WithFilterTags(filterTags *string) *GetProjectSSHKeysParams { + o.SetFilterTags(filterTags) + return o +} + +func (o *GetProjectSSHKeysParams) SetFilterTags(filterTags *string) { + o.FilterTags = filterTags +} + // WriteToRequest writes these params to a swagger request func (o *GetProjectSSHKeysParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -150,6 +161,22 @@ func (o *GetProjectSSHKeysParams) WriteToRequest(r runtime.ClientRequest, reg st return err } + if o.FilterTags != nil { + + var qrFilterTags string + + if o.FilterTags != nil { + qrFilterTags = *o.FilterTags + } + qFilterTags := qrFilterTags + if qFilterTags != "" { + + if err := r.SetQueryParam("filter[tags]", qFilterTags); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/client/ssh_keys/put_project_ssh_key_responses.go b/client/ssh_keys/put_project_ssh_key_responses.go index c0c1a9c..cb8ad7b 100755 --- a/client/ssh_keys/put_project_ssh_key_responses.go +++ b/client/ssh_keys/put_project_ssh_key_responses.go @@ -495,6 +495,8 @@ type PutProjectSSHKeyParamsBodyDataAttributes struct { // Name of the SSH Key Name string `json:"name,omitempty"` + + Tags []string `json:"tags,omitempty"` } // Validate validates this put project SSH key params body data attributes diff --git a/models/ssh_key_data.go b/models/ssh_key_data.go index cc059d9..c56ed1e 100755 --- a/models/ssh_key_data.go +++ b/models/ssh_key_data.go @@ -169,6 +169,10 @@ func (m *SSHKeyData) TableRow() table.Row { Label: "ID", Value: table.String(m.ID), }, + "tags": table.Cell{ + Label: "Tags", + Value: table.StringList(tags(attr.Tags), ","), + }, "name": table.Cell{ Label: "Name", Value: table.String(attr.Name), @@ -193,7 +197,7 @@ func (m *SSHKeyData) TableRow() table.Row { // // swagger:model SSHKeyDataAttributes type SSHKeyDataAttributes struct { - + Tags []*TagsIncude `json:"tags,omitempty"` // created at CreatedAt string `json:"created_at,omitempty"` From f17589e958b207e61e1483bfe0edab41a12deef0 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Sun, 31 Mar 2024 14:47:51 -0300 Subject: [PATCH 23/28] feat: Add tags to projects --- cli/get_projects_operation.go | 45 +++++++++++++++++++++ cli/update_project_operation.go | 6 +++ client/projects/get_projects_parameters.go | 27 +++++++++++++ client/projects/update_project_responses.go | 2 + models/project.go | 6 +++ 5 files changed, 86 insertions(+) diff --git a/cli/get_projects_operation.go b/cli/get_projects_operation.go index 46f5ada..57b3361 100755 --- a/cli/get_projects_operation.go +++ b/cli/get_projects_operation.go @@ -53,6 +53,9 @@ func runOperationProjectsGetProjects(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationProjectsGetProjectsFilterSlugFlag(params, "", cmd); err != nil { return err } + if err, _ := retrieveOperationProjectsGetProjectsFilterTagsFlag(params, "", cmd); err != nil { + return err + } if dryRun { logDebugf("dry-run flag specified. Skip sending request.") @@ -91,6 +94,9 @@ func registerOperationProjectsGetProjectsParamFlags(cmd *cobra.Command) error { if err := registerOperationProjectsGetProjectsFilterSlugParamFlags("", cmd); err != nil { return err } + if err := registerOperationProjectsGetProjectsFilterTagsFlag("", cmd); err != nil { + return err + } return nil } @@ -199,6 +205,24 @@ func registerOperationProjectsGetProjectsFilterSlugParamFlags(cmdPrefix string, return nil } +func registerOperationProjectsGetProjectsFilterTagsFlag(cmdPrefix string, cmd *cobra.Command) error { + + filterTagsDescription := `The Tags to filter by` + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + var filterTagsFlagDefault = "" + + _ = cmd.PersistentFlags().String(filterTagsFlagName, filterTagsFlagDefault, filterTagsDescription) + + return nil +} + func retrieveOperationProjectsGetProjectsExtraFieldsProjectsFlag(m *projects.GetProjectsParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { retAdded := false if cmd.Flags().Changed("extra_fields[projects]") { @@ -319,3 +343,24 @@ func retrieveOperationProjectsGetProjectsFilterSlugFlag(m *projects.GetProjectsP } return nil, retAdded } + +func retrieveOperationProjectsGetProjectsFilterTagsFlag(m *projects.GetProjectsParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { + retAdded := false + if cmd.Flags().Changed("tags") { + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + filterTagsFlagValue, err := cmd.Flags().GetString(filterTagsFlagName) + if err != nil { + return err, false + } + m.FilterTags = &filterTagsFlagValue + + } + return nil, retAdded +} diff --git a/cli/update_project_operation.go b/cli/update_project_operation.go index 57cc74b..3c6712d 100755 --- a/cli/update_project_operation.go +++ b/cli/update_project_operation.go @@ -66,6 +66,12 @@ func (o *UpdateProjectOperation) registerFlags(cmd *cobra.Command) { Description: "The project name. Must be unique.", Required: false, }, + &cmdflag.StringSlice{ + Name: "tags", + Label: "Tags", + Description: "Tags", + Required: false, + }, &cmdflag.String{ Name: "description", Label: "Description", diff --git a/client/projects/get_projects_parameters.go b/client/projects/get_projects_parameters.go index 483b793..8c2c096 100755 --- a/client/projects/get_projects_parameters.go +++ b/client/projects/get_projects_parameters.go @@ -97,6 +97,8 @@ type GetProjectsParams struct { */ FilterSlug *string + FilterTags *string + timeout time.Duration Context context.Context HTTPClient *http.Client @@ -221,6 +223,15 @@ func (o *GetProjectsParams) SetFilterSlug(filterSlug *string) { o.FilterSlug = filterSlug } +func (o *GetProjectsParams) WithFilterTags(filterTags *string) *GetProjectsParams { + o.SetFilterTags(filterTags) + return o +} + +func (o *GetProjectsParams) SetFilterTags(filterTags *string) { + o.FilterTags = filterTags +} + // WriteToRequest writes these params to a swagger request func (o *GetProjectsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -335,6 +346,22 @@ func (o *GetProjectsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.R } } + if o.FilterTags != nil { + + var qrFilterTags string + + if o.FilterTags != nil { + qrFilterTags = *o.FilterTags + } + qFilterTags := qrFilterTags + if qFilterTags != "" { + + if err := r.SetQueryParam("filter[tags]", qFilterTags); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/client/projects/update_project_responses.go b/client/projects/update_project_responses.go index bb9d1a7..3782018 100755 --- a/client/projects/update_project_responses.go +++ b/client/projects/update_project_responses.go @@ -549,6 +549,8 @@ type UpdateProjectParamsBodyDataAttributes struct { // name Name string `json:"name,omitempty"` + + Tags []string `json:"tags,omitempty"` } // Validate validates this update project params body data attributes diff --git a/models/project.go b/models/project.go index d34f48b..65beb97 100755 --- a/models/project.go +++ b/models/project.go @@ -122,6 +122,10 @@ func (m *Project) TableRow() table.Row { Label: "ID", Value: table.String(m.ID), }, + "tags": table.Cell{ + Label: "Tags", + Value: table.StringList(tags(attr.Tags), ","), + }, "name": table.Cell{ Label: "Name", Value: table.String(attr.Name), @@ -166,6 +170,8 @@ func (m *Project) TableRow() table.Row { // swagger:model ProjectAttributes type ProjectAttributes struct { + Tags []*TagsIncude `json:"tags,omitempty"` + // billing Billing *ProjectAttributesBilling `json:"billing,omitempty"` From 47ec130426f580ff05fecfbf3c752d35c17e0362 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Sun, 31 Mar 2024 14:48:16 -0300 Subject: [PATCH 24/28] feat: Add tags to virtual networks --- cli/get_virtual_networks_operation.go | 43 +++++++++++++++++++ cli/update_virtual_network_operation.go | 6 +++ .../get_virtual_networks_parameters.go | 27 ++++++++++++ .../update_virtual_network_responses.go | 3 +- models/virtual_network.go | 5 +++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/cli/get_virtual_networks_operation.go b/cli/get_virtual_networks_operation.go index 5b12723..99bac9f 100755 --- a/cli/get_virtual_networks_operation.go +++ b/cli/get_virtual_networks_operation.go @@ -41,6 +41,9 @@ func runOperationVirtualNetworksGetVirtualNetworks(cmd *cobra.Command, args []st if err, _ := retrieveOperationVirtualNetworksGetVirtualNetworksFilterProjectFlag(params, "", cmd); err != nil { return err } + if err, _ := retrieveOperationVirtualNetworksGetVirtualNetworksFilterTagsFlag(params, "", cmd); err != nil { + return err + } if dryRun { logDebugf("dry-run flag specified. Skip sending request.") @@ -68,6 +71,9 @@ func registerOperationVirtualNetworksGetVirtualNetworksParamFlags(cmd *cobra.Com if err := registerOperationVirtualNetworksGetVirtualNetworksFilterProjectParamFlags("", cmd); err != nil { return err } + if err := registerOperationVirtualNetworksGetVirtualNetworksFilterTagsFlag("", cmd); err != nil { + return err + } return nil } @@ -105,6 +111,23 @@ func registerOperationVirtualNetworksGetVirtualNetworksFilterProjectParamFlags(c return nil } +func registerOperationVirtualNetworksGetVirtualNetworksFilterTagsFlag(cmdPrefix string, cmd *cobra.Command) error { + + filterTagsDescription := `The Tags to filter by` + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + var filterTagsFlagDefault = "" + + _ = cmd.PersistentFlags().String(filterTagsFlagName, filterTagsFlagDefault, filterTagsDescription) + + return nil +} func retrieveOperationVirtualNetworksGetVirtualNetworksFilterLocationFlag(m *virtual_networks.GetVirtualNetworksParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { retAdded := false @@ -146,3 +169,23 @@ func retrieveOperationVirtualNetworksGetVirtualNetworksFilterProjectFlag(m *virt } return nil, retAdded } +func retrieveOperationVirtualNetworksGetVirtualNetworksFilterTagsFlag(m *virtual_networks.GetVirtualNetworksParams, cmdPrefix string, cmd *cobra.Command) (error, bool) { + retAdded := false + if cmd.Flags().Changed("tags") { + + var filterTagsFlagName string + if cmdPrefix == "" { + filterTagsFlagName = "tags" + } else { + filterTagsFlagName = fmt.Sprintf("%v.tags", cmdPrefix) + } + + filterTagsFlagValue, err := cmd.Flags().GetString(filterTagsFlagName) + if err != nil { + return err, false + } + m.FilterTags = &filterTagsFlagValue + + } + return nil, retAdded +} diff --git a/cli/update_virtual_network_operation.go b/cli/update_virtual_network_operation.go index 79904db..c4e1253 100755 --- a/cli/update_virtual_network_operation.go +++ b/cli/update_virtual_network_operation.go @@ -51,6 +51,12 @@ func (o *UpdateVirtualNetworkOperation) registerFlags(cmd *cobra.Command) { } bodyFlagsSchema := &cmdflag.FlagsSchema{ + &cmdflag.StringSlice{ + Name: "tags", + Label: "Tags", + Description: "Tags", + Required: false, + }, &cmdflag.String{ Name: "description", Label: "Description", diff --git a/client/virtual_networks/get_virtual_networks_parameters.go b/client/virtual_networks/get_virtual_networks_parameters.go index dceee28..6e087a7 100755 --- a/client/virtual_networks/get_virtual_networks_parameters.go +++ b/client/virtual_networks/get_virtual_networks_parameters.go @@ -60,6 +60,8 @@ GetVirtualNetworksParams contains all the parameters to send to the API endpoint Typically these are written to a http.Request. */ type GetVirtualNetworksParams struct { + FilterTags *string + /* FilterLocation. The location slug to filter by @@ -152,6 +154,15 @@ func (o *GetVirtualNetworksParams) SetFilterProject(filterProject *string) { o.FilterProject = filterProject } +func (o *GetVirtualNetworksParams) WithFilterTags(filterTags *string) *GetVirtualNetworksParams { + o.SetFilterTags(filterTags) + return o +} + +func (o *GetVirtualNetworksParams) SetFilterTags(filterTags *string) { + o.FilterTags = filterTags +} + // WriteToRequest writes these params to a swagger request func (o *GetVirtualNetworksParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -198,6 +209,22 @@ func (o *GetVirtualNetworksParams) WriteToRequest(r runtime.ClientRequest, reg s } } + if o.FilterTags != nil { + + var qrFilterTags string + + if o.FilterTags != nil { + qrFilterTags = *o.FilterTags + } + qFilterTags := qrFilterTags + if qFilterTags != "" { + + if err := r.SetQueryParam("filter[tags]", qFilterTags); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/client/virtual_networks/update_virtual_network_responses.go b/client/virtual_networks/update_virtual_network_responses.go index a4af495..9b0ecf0 100755 --- a/client/virtual_networks/update_virtual_network_responses.go +++ b/client/virtual_networks/update_virtual_network_responses.go @@ -369,9 +369,10 @@ UpdateVirtualNetworkParamsBodyDataAttributes update virtual network params body swagger:model UpdateVirtualNetworkParamsBodyDataAttributes */ type UpdateVirtualNetworkParamsBodyDataAttributes struct { - // description Description string `json:"description,omitempty"` + + Tags []string `json:"tags,omitempty"` } // Validate validates this update virtual network params body data attributes diff --git a/models/virtual_network.go b/models/virtual_network.go index 37e4a55..4d6d921 100755 --- a/models/virtual_network.go +++ b/models/virtual_network.go @@ -167,6 +167,10 @@ func (m *VirtualNetwork) TableRow() table.Row { Label: "ID", Value: table.String(m.ID), }, + "tags": table.Cell{ + Label: "Tags", + Value: table.StringList(tags(attr.Tags), ","), + }, "vid": table.Cell{ Label: "VID", Value: table.Int(attr.Vid), @@ -200,6 +204,7 @@ func virtualNetworkLocation(attributes *VirtualNetworkAttributes) string { // // swagger:model VirtualNetworkAttributes type VirtualNetworkAttributes struct { + Tags []*TagsIncude `json:"tags,omitempty"` // Amount of devices assigned to the virtual network AssignmentsCount int64 `json:"assignments_count,omitempty"` From b8e45a0888bdb5b94b8f2fb94d3a24c2133177d3 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Mon, 1 Apr 2024 19:57:16 -0300 Subject: [PATCH 25/28] chore: refactor preparing to new cmd structure --- ...assign_server_virtual_network_operation.go | 7 ++-- cli/cli.go | 38 ++++--------------- cli/create_project_operation.go | 7 ++-- cli/create_server_operation.go | 7 ++-- cli/create_server_reinstall_operation.go | 7 ++-- cli/create_virtual_network_operation.go | 7 ++-- cli/delete_api_key_operation.go | 7 ++-- cli/delete_project_operation.go | 7 ++-- cli/delete_project_ssh_key_operation.go | 7 ++-- ..._virtual_networks_assignments_operation.go | 7 ++-- cli/destroy_server_operation.go | 7 ++-- cli/destroy_virtual_network_operation.go | 7 ++-- cli/get_api_keys_operation.go | 7 ++-- cli/get_bandwidth_plans_operation.go | 7 ++-- cli/get_plan_operation.go | 7 ++-- cli/get_plans_operation.go | 7 ++-- cli/get_project_operation.go | 7 ++-- cli/get_project_ssh_key_operation.go | 7 ++-- cli/get_project_ssh_keys_operation.go | 7 ++-- cli/get_projects_operation.go | 7 ++-- cli/get_server_operation.go | 7 ++-- cli/get_servers_operation.go | 7 ++-- cli/get_virtual_network_operation.go | 7 ++-- ..._virtual_networks_assignments_operation.go | 7 ++-- cli/get_virtual_networks_operation.go | 7 ++-- cli/post_api_key_operation.go | 7 ++-- cli/post_project_ssh_key_operation.go | 7 ++-- cli/put_project_ssh_key_operation.go | 7 ++-- cli/server_schedule_deletion_operation.go | 7 ++-- cli/server_unschedule_deletion_operation.go | 7 ++-- cli/update_api_key_operation.go | 7 ++-- cli/update_project_operation.go | 7 ++-- cli/update_server_operation.go | 7 ++-- cli/update_virtual_network_operation.go | 7 ++-- cmd/lsh/lsh.go | 35 +++++++++++++++++ cmd/lsh/main.go | 25 ------------ cmd/root.go | 35 +++++++++++++++++ main.go | 9 +++++ 38 files changed, 218 insertions(+), 155 deletions(-) create mode 100644 cmd/lsh/lsh.go delete mode 100755 cmd/lsh/main.go create mode 100644 cmd/root.go create mode 100644 main.go diff --git a/cli/assign_server_virtual_network_operation.go b/cli/assign_server_virtual_network_operation.go index da71c69..ee08464 100755 --- a/cli/assign_server_virtual_network_operation.go +++ b/cli/assign_server_virtual_network_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/virtual_network_assignments" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -72,8 +73,8 @@ func (o *CreateVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [ params := virtual_network_assignments.NewAssignServerVirtualNetworkParams() o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -83,7 +84,7 @@ func (o *CreateVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [ return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/cli.go b/cli/cli.go index 26a6ac6..6228077 100755 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,12 +2,12 @@ package cli import ( "fmt" - "log" "os" "path" "path/filepath" "github.com/latitudesh/lsh/client" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/version" "github.com/go-openapi/runtime" @@ -18,26 +18,12 @@ import ( "github.com/spf13/viper" ) -// debug flag indicating that cli should output debug logs -var debug bool - // config file location var configFile string -// dry run flag -var dryRun bool - // name of the executable var exeName string = filepath.Base(os.Args[0]) -// logDebugf writes debug log to stdout -func logDebugf(format string, v ...interface{}) { - if !debug { - return - } - log.Printf(format, v...) -} - // depth of recursion to construct model flags var maxDepth int = 5 @@ -49,7 +35,7 @@ func makeClient(cmd *cobra.Command, args []string) (*client.LatitudeShAPI, error scheme := viper.GetString("scheme") r := httptransport.New(hostname, basePath, []string{scheme}) - r.SetDebug(debug) + r.SetDebug(lsh.Debug) // set custom producer and consumer to use the default ones r.Consumers["application/json"] = runtime.JSONConsumer() @@ -64,20 +50,14 @@ func makeClient(cmd *cobra.Command, args []string) (*client.LatitudeShAPI, error r.DefaultAuthentication = auth appCli := client.New(r, strfmt.Default) - logDebugf("Server url: %v://%v", scheme, hostname) + lsh.LogDebugf("Server url: %v://%v", scheme, hostname) return appCli, nil } // MakeRootCmd returns the root cmd -func MakeRootCmd() (*cobra.Command, error) { +func MakeRootCmd(rootCmd *cobra.Command) (*cobra.Command, error) { cobra.OnInitialize(initViperConfigs) - // Use executable name as the command name - rootCmd := &cobra.Command{ - Use: exeName, - Version: version.Version, - } - // Edit commands template rootCmd.SetVersionTemplate(fmt.Sprintf("lsh %s\n", rootCmd.Version)) @@ -100,12 +80,8 @@ func MakeRootCmd() (*cobra.Command, error) { var noInput bool rootCmd.PersistentFlags().BoolVar(&noInput, "no-input", false, "skip interactive mode") - // configure debug flag - rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "output debug logs") // configure config location rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file path") - // configure dry run flag - rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "do not send the request to server") // register security flags if err := registerAuthInoWriterFlags(rootCmd); err != nil { @@ -185,10 +161,10 @@ func initViperConfigs() { } if err := viper.ReadInConfig(); err != nil { - logDebugf("Error: loading config file: %v", err) + lsh.LogDebugf("Error: loading config file: %v", err) return } - logDebugf("Using config file: %v", viper.ConfigFileUsed()) + lsh.LogDebugf("Using config file: %v", viper.ConfigFileUsed()) } // registerAuthInoWriterFlags registers all flags needed to perform authentication @@ -213,7 +189,7 @@ func makeAuthInfoWriter(cmd *cobra.Command) (runtime.ClientAuthInfoWriter, error auths = append(auths, httptransport.APIKeyAuth("User-Agent", "header", userAgent)) } if len(auths) == 0 { - logDebugf("Warning: No auth params detected.") + lsh.LogDebugf("Warning: No auth params detected.") return nil, nil } // compose all auths together diff --git a/cli/create_project_operation.go b/cli/create_project_operation.go index 4805d41..e32685d 100755 --- a/cli/create_project_operation.go +++ b/cli/create_project_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/projects" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -86,8 +87,8 @@ func (o *CreateProjectOperation) run(cmd *cobra.Command, args []string) error { params := projects.NewCreateProjectParams() o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -97,7 +98,7 @@ func (o *CreateProjectOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/create_server_operation.go b/cli/create_server_operation.go index f53cb8b..b0f250d 100755 --- a/cli/create_server_operation.go +++ b/cli/create_server_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -126,8 +127,8 @@ func (o *CreateServerOperation) run(cmd *cobra.Command, args []string) error { params := servers.NewCreateServerParams() o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -137,7 +138,7 @@ func (o *CreateServerOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } diff --git a/cli/create_server_reinstall_operation.go b/cli/create_server_reinstall_operation.go index 0e8fd49..cf234c0 100755 --- a/cli/create_server_reinstall_operation.go +++ b/cli/create_server_reinstall_operation.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/server_reinstall" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -121,8 +122,8 @@ func (o *CreateServerReinstallOperation) run(cmd *cobra.Command, args []string) return nil } - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -132,7 +133,7 @@ func (o *CreateServerReinstallOperation) run(cmd *cobra.Command, args []string) return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/create_virtual_network_operation.go b/cli/create_virtual_network_operation.go index 2a71f3b..e3b6d46 100755 --- a/cli/create_virtual_network_operation.go +++ b/cli/create_virtual_network_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/virtual_networks" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -80,8 +81,8 @@ func (o *CreateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e params := virtual_networks.NewCreateVirtualNetworkParams() o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -91,7 +92,7 @@ func (o *CreateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/delete_api_key_operation.go b/cli/delete_api_key_operation.go index 4cb02a3..8900b83 100755 --- a/cli/delete_api_key_operation.go +++ b/cli/delete_api_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/api_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -64,8 +65,8 @@ func (o *DeleteAPIKeyOperation) run(cmd *cobra.Command, args []string) error { params := api_keys.NewDeleteAPIKeyParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -75,7 +76,7 @@ func (o *DeleteAPIKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/delete_project_operation.go b/cli/delete_project_operation.go index 690c3f6..0492301 100755 --- a/cli/delete_project_operation.go +++ b/cli/delete_project_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/projects" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -64,8 +65,8 @@ func (o *DeleteProjectOperation) run(cmd *cobra.Command, args []string) error { params := projects.NewDeleteProjectParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -75,7 +76,7 @@ func (o *DeleteProjectOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/delete_project_ssh_key_operation.go b/cli/delete_project_ssh_key_operation.go index e02ada7..799148d 100755 --- a/cli/delete_project_ssh_key_operation.go +++ b/cli/delete_project_ssh_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/ssh_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -70,8 +71,8 @@ func (o *DeleteSSHKeyOperation) run(cmd *cobra.Command, args []string) error { params := ssh_keys.NewDeleteProjectSSHKeyParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -81,7 +82,7 @@ func (o *DeleteSSHKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/delete_virtual_networks_assignments_operation.go b/cli/delete_virtual_networks_assignments_operation.go index 9cee3b4..b182db5 100755 --- a/cli/delete_virtual_networks_assignments_operation.go +++ b/cli/delete_virtual_networks_assignments_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/virtual_network_assignments" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -67,8 +68,8 @@ func (o *DeleteVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [ params := virtual_network_assignments.NewDeleteVirtualNetworksAssignmentsParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -78,7 +79,7 @@ func (o *DeleteVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [ return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/destroy_server_operation.go b/cli/destroy_server_operation.go index 015f3c5..85ebcdc 100755 --- a/cli/destroy_server_operation.go +++ b/cli/destroy_server_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -64,8 +65,8 @@ func (o *DestroyServerOperation) run(cmd *cobra.Command, args []string) error { params := servers.NewDestroyServerParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -75,7 +76,7 @@ func (o *DestroyServerOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/destroy_virtual_network_operation.go b/cli/destroy_virtual_network_operation.go index 8c7bd30..7d156aa 100755 --- a/cli/destroy_virtual_network_operation.go +++ b/cli/destroy_virtual_network_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/virtual_networks" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -64,8 +65,8 @@ func (o *DeleteVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e params := virtual_networks.NewDestroyVirtualNetworkParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -75,7 +76,7 @@ func (o *DeleteVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/get_api_keys_operation.go b/cli/get_api_keys_operation.go index f23cdc3..43f5d12 100755 --- a/cli/get_api_keys_operation.go +++ b/cli/get_api_keys_operation.go @@ -5,6 +5,7 @@ package cli import ( "github.com/latitudesh/lsh/client/api_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -29,9 +30,9 @@ func runOperationAPIKeysGetAPIKeys(cmd *cobra.Command, args []string) error { } // retrieve flag values from cmd and fill params params := api_keys.NewGetAPIKeysParams() - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -41,7 +42,7 @@ func runOperationAPIKeysGetAPIKeys(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_bandwidth_plans_operation.go b/cli/get_bandwidth_plans_operation.go index 1646c61..443e0e2 100755 --- a/cli/get_bandwidth_plans_operation.go +++ b/cli/get_bandwidth_plans_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/plans" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -38,9 +39,9 @@ func runOperationPlansGetBandwidthPlans(cmd *cobra.Command, args []string) error if err, _ := retrieveOperationPlansGetBandwidthPlansFilterIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -50,7 +51,7 @@ func runOperationPlansGetBandwidthPlans(cmd *cobra.Command, args []string) error return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_plan_operation.go b/cli/get_plan_operation.go index ba6fbdc..5d25db0 100755 --- a/cli/get_plan_operation.go +++ b/cli/get_plan_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/plans" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -38,9 +39,9 @@ func runOperationPlansGetPlan(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationPlansGetPlanPlanIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -50,7 +51,7 @@ func runOperationPlansGetPlan(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_plans_operation.go b/cli/get_plans_operation.go index c88ad57..4c6cc4b 100755 --- a/cli/get_plans_operation.go +++ b/cli/get_plans_operation.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/plans" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -72,9 +73,9 @@ func runOperationPlansGetPlans(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationPlansGetPlansFilterStockLevelFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -84,7 +85,7 @@ func runOperationPlansGetPlans(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_project_operation.go b/cli/get_project_operation.go index 531f7c8..1517a88 100755 --- a/cli/get_project_operation.go +++ b/cli/get_project_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/projects" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -41,9 +42,9 @@ func runOperationProjectsGetProject(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationProjectsGetProjectIDOrSlugFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -53,7 +54,7 @@ func runOperationProjectsGetProject(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_project_ssh_key_operation.go b/cli/get_project_ssh_key_operation.go index a897206..8104eff 100755 --- a/cli/get_project_ssh_key_operation.go +++ b/cli/get_project_ssh_key_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/ssh_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -41,9 +42,9 @@ func runOperationSSHKeysGetProjectSSHKey(cmd *cobra.Command, args []string) erro if err, _ := retrieveOperationSSHKeysGetProjectSSHKeySSHKeyIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -53,7 +54,7 @@ func runOperationSSHKeysGetProjectSSHKey(cmd *cobra.Command, args []string) erro return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_project_ssh_keys_operation.go b/cli/get_project_ssh_keys_operation.go index 0da30a6..a97fdb2 100755 --- a/cli/get_project_ssh_keys_operation.go +++ b/cli/get_project_ssh_keys_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/ssh_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -41,9 +42,9 @@ func runOperationSSHKeysGetProjectSSHKeys(cmd *cobra.Command, args []string) err if err, _ := retrieveOperationSSHKeysFilterTagsFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -53,7 +54,7 @@ func runOperationSSHKeysGetProjectSSHKeys(cmd *cobra.Command, args []string) err return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_projects_operation.go b/cli/get_projects_operation.go index 57b3361..cf8964a 100755 --- a/cli/get_projects_operation.go +++ b/cli/get_projects_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/projects" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -56,9 +57,9 @@ func runOperationProjectsGetProjects(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationProjectsGetProjectsFilterTagsFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -68,7 +69,7 @@ func runOperationProjectsGetProjects(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_server_operation.go b/cli/get_server_operation.go index 122d77f..c73e8b4 100755 --- a/cli/get_server_operation.go +++ b/cli/get_server_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -41,9 +42,9 @@ func runOperationServersGetServer(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationServersGetServerServerIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -53,7 +54,7 @@ func runOperationServersGetServer(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_servers_operation.go b/cli/get_servers_operation.go index 287ba65..115fee8 100755 --- a/cli/get_servers_operation.go +++ b/cli/get_servers_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -89,9 +90,9 @@ func runOperationServersGetServers(cmd *cobra.Command, args []string) error { if err, _ := retrieveOperationServersGetServersFilterTagsFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -101,7 +102,7 @@ func runOperationServersGetServers(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_virtual_network_operation.go b/cli/get_virtual_network_operation.go index b07ee6d..26d94bd 100755 --- a/cli/get_virtual_network_operation.go +++ b/cli/get_virtual_network_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/virtual_networks" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -38,9 +39,9 @@ func runOperationVirtualNetworksGetVirtualNetwork(cmd *cobra.Command, args []str if err, _ := retrieveOperationVirtualNetworksGetVirtualNetworkIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -50,7 +51,7 @@ func runOperationVirtualNetworksGetVirtualNetwork(cmd *cobra.Command, args []str return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_virtual_networks_assignments_operation.go b/cli/get_virtual_networks_assignments_operation.go index 20019a9..b256b3f 100755 --- a/cli/get_virtual_networks_assignments_operation.go +++ b/cli/get_virtual_networks_assignments_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/virtual_network_assignments" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -44,9 +45,9 @@ func runOperationVirtualNetworkAssignmentsGetVirtualNetworksAssignments(cmd *cob if err, _ := retrieveOperationVirtualNetworkAssignmentsGetVirtualNetworksAssignmentsFilterVirtualNetworkIDFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -56,7 +57,7 @@ func runOperationVirtualNetworkAssignmentsGetVirtualNetworksAssignments(cmd *cob return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/get_virtual_networks_operation.go b/cli/get_virtual_networks_operation.go index 99bac9f..a036066 100755 --- a/cli/get_virtual_networks_operation.go +++ b/cli/get_virtual_networks_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/virtual_networks" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/utils" "github.com/spf13/cobra" @@ -44,9 +45,9 @@ func runOperationVirtualNetworksGetVirtualNetworks(cmd *cobra.Command, args []st if err, _ := retrieveOperationVirtualNetworksGetVirtualNetworksFilterTagsFlag(params, "", cmd); err != nil { return err } - if dryRun { + if lsh.DryRun { - logDebugf("dry-run flag specified. Skip sending request.") + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -56,7 +57,7 @@ func runOperationVirtualNetworksGetVirtualNetworks(cmd *cobra.Command, args []st return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } diff --git a/cli/post_api_key_operation.go b/cli/post_api_key_operation.go index c743e12..6b54093 100755 --- a/cli/post_api_key_operation.go +++ b/cli/post_api_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/api_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -64,8 +65,8 @@ func (o *CreateAPIKeyOperation) run(cmd *cobra.Command, args []string) error { params := api_keys.NewPostAPIKeyParams() o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -75,7 +76,7 @@ func (o *CreateAPIKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/post_project_ssh_key_operation.go b/cli/post_project_ssh_key_operation.go index 84d6240..1f839e5 100755 --- a/cli/post_project_ssh_key_operation.go +++ b/cli/post_project_ssh_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/ssh_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -84,8 +85,8 @@ func (o *CreateSSHKeyOperation) run(cmd *cobra.Command, args []string) error { o.PathParamFlags.AssignValues(params) o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -95,7 +96,7 @@ func (o *CreateSSHKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/put_project_ssh_key_operation.go b/cli/put_project_ssh_key_operation.go index 0d85422..81bd184 100755 --- a/cli/put_project_ssh_key_operation.go +++ b/cli/put_project_ssh_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/ssh_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -91,8 +92,8 @@ func (o *UpdateSSHKeyOperation) run(cmd *cobra.Command, args []string) error { o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) params.Body.Data.ID = params.SSHKeyID - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -102,7 +103,7 @@ func (o *UpdateSSHKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/server_schedule_deletion_operation.go b/cli/server_schedule_deletion_operation.go index b06826d..3a78dba 100755 --- a/cli/server_schedule_deletion_operation.go +++ b/cli/server_schedule_deletion_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -67,8 +68,8 @@ func (o *ScheduleServerDeletionOperation) run(cmd *cobra.Command, args []string) params := servers.NewServerScheduleDeletionParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -78,7 +79,7 @@ func (o *ScheduleServerDeletionOperation) run(cmd *cobra.Command, args []string) return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/server_unschedule_deletion_operation.go b/cli/server_unschedule_deletion_operation.go index 14b33db..08af46d 100755 --- a/cli/server_unschedule_deletion_operation.go +++ b/cli/server_unschedule_deletion_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -67,8 +68,8 @@ func (o *UnscheduleServerDeletionOperation) run(cmd *cobra.Command, args []strin params := servers.NewServerUnscheduleDeletionParams() o.PathParamFlags.AssignValues(params) - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -78,7 +79,7 @@ func (o *UnscheduleServerDeletionOperation) run(cmd *cobra.Command, args []strin return nil } - if !debug { + if !lsh.Debug { response.Render() } return nil diff --git a/cli/update_api_key_operation.go b/cli/update_api_key_operation.go index 2a2c122..4a04525 100755 --- a/cli/update_api_key_operation.go +++ b/cli/update_api_key_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/api_keys" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -79,8 +80,8 @@ func (o *UpdateAPIKeyOperation) run(cmd *cobra.Command, args []string) error { o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) params.Body.Data.ID = params.ID - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -90,7 +91,7 @@ func (o *UpdateAPIKeyOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/update_project_operation.go b/cli/update_project_operation.go index 3c6712d..4e3a79f 100755 --- a/cli/update_project_operation.go +++ b/cli/update_project_operation.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/latitudesh/lsh/client/projects" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -121,8 +122,8 @@ func (o *UpdateProjectOperation) run(cmd *cobra.Command, args []string) error { return nil } - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -132,7 +133,7 @@ func (o *UpdateProjectOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/update_server_operation.go b/cli/update_server_operation.go index 0ca834f..c161c1f 100755 --- a/cli/update_server_operation.go +++ b/cli/update_server_operation.go @@ -5,6 +5,7 @@ import ( "github.com/go-openapi/swag" "github.com/latitudesh/lsh/client/servers" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/api/resource" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -106,8 +107,8 @@ func (o *UpdateServerOperation) run(cmd *cobra.Command, args []string) error { return nil } - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -117,7 +118,7 @@ func (o *UpdateServerOperation) run(cmd *cobra.Command, args []string) error { return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cli/update_virtual_network_operation.go b/cli/update_virtual_network_operation.go index c4e1253..be40279 100755 --- a/cli/update_virtual_network_operation.go +++ b/cli/update_virtual_network_operation.go @@ -2,6 +2,7 @@ package cli import ( "github.com/latitudesh/lsh/client/virtual_networks" + "github.com/latitudesh/lsh/cmd/lsh" "github.com/latitudesh/lsh/internal/cmdflag" "github.com/latitudesh/lsh/internal/utils" @@ -85,8 +86,8 @@ func (o *UpdateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes) params.Body.Data.ID = params.VirtualNetworkID - if dryRun { - logDebugf("dry-run flag specified. Skip sending request.") + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") return nil } @@ -96,7 +97,7 @@ func (o *UpdateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e return nil } - if !debug { + if !lsh.Debug { utils.Render(response.GetData()) } return nil diff --git a/cmd/lsh/lsh.go b/cmd/lsh/lsh.go new file mode 100644 index 0000000..4b8a7ea --- /dev/null +++ b/cmd/lsh/lsh.go @@ -0,0 +1,35 @@ +// Package to configure options that should be acessible througout all commands +package lsh + +import ( + "log" + + sdk "github.com/latitudesh/latitudesh-go" + "github.com/spf13/viper" +) + +// Dry run flag +var DryRun bool + +// Debug flag indicating that cli should output debug logs +var Debug bool + +// LogDebugf writes debug log to stdout +func LogDebugf(format string, v ...interface{}) { + if !Debug { + return + } + log.Printf(format, v...) +} + +func NewClient() *sdk.Client { + AuthorizationKey := viper.GetString("Authorization") + + c := sdk.NewClientWithAuth("latitudesh", " ", nil) + + if AuthorizationKey != "" { + c = sdk.NewClientWithAuth("latitudesh", AuthorizationKey, nil) + } + + return c +} diff --git a/cmd/lsh/main.go b/cmd/lsh/main.go deleted file mode 100755 index 87061cf..0000000 --- a/cmd/lsh/main.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package main - -import ( - "fmt" - "os" - - "github.com/latitudesh/lsh/cli" -) - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -func main() { - rootCmd, err := cli.MakeRootCmd() - if err != nil { - fmt.Println("Cmd construction error: ", err) - os.Exit(1) - } - - if err := rootCmd.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..de7f9e0 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,35 @@ +package cmd + +import ( + "log" + "os" + "path/filepath" + + "github.com/latitudesh/lsh/cli" + "github.com/latitudesh/lsh/cmd/lsh" + "github.com/latitudesh/lsh/internal/version" + "github.com/spf13/cobra" +) + +var ( + exeName string = filepath.Base(os.Args[0]) + + // Use executable name as the command name + rootCmd = &cobra.Command{ + Use: exeName, + Version: version.Version, + } +) + +// Execute executes the root command. +func Execute() (*cobra.Command, error) { + cmd, err := cli.MakeRootCmd(rootCmd) + if err != nil { + log.Fatal("Cmd construction error: ", err) + } + + rootCmd.PersistentFlags().BoolVar(&lsh.DryRun, "dry-run", false, "do not send the request to server") + rootCmd.PersistentFlags().BoolVar(&lsh.Debug, "debug", false, "output debug logs") + + return cmd, cmd.Execute() +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..78c6c9c --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/latitudesh/lsh/cmd" +) + +func main() { + cmd.Execute() +} From 7363eb782a8d81cbcc6f4b4a93884646b8ebec7e Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Mon, 1 Apr 2024 19:57:57 -0300 Subject: [PATCH 26/28] feat: Add tags command --- cmd/build_tags.go | 17 +++++++ cmd/tags/create.go | 92 ++++++++++++++++++++++++++++++++++ cmd/tags/destroy.go | 73 +++++++++++++++++++++++++++ cmd/tags/list.go | 54 ++++++++++++++++++++ cmd/tags/tag.go | 83 +++++++++++++++++++++++++++++++ cmd/tags/update.go | 117 ++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +- go.sum | 4 ++ 8 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 cmd/build_tags.go create mode 100644 cmd/tags/create.go create mode 100644 cmd/tags/destroy.go create mode 100644 cmd/tags/list.go create mode 100644 cmd/tags/tag.go create mode 100644 cmd/tags/update.go diff --git a/cmd/build_tags.go b/cmd/build_tags.go new file mode 100644 index 0000000..b1404ee --- /dev/null +++ b/cmd/build_tags.go @@ -0,0 +1,17 @@ +package cmd + +import ( + tags "github.com/latitudesh/lsh/cmd/tags" + cobra "github.com/spf13/cobra" +) + +func init() { + tagsCmd.AddCommand(tags.NewDestroyCmd()) + tagsCmd.AddCommand(tags.NewUpdateCmd()) + tagsCmd.AddCommand(tags.NewListCmd()) + tagsCmd.AddCommand(tags.NewCreateCmd()) + + rootCmd.AddCommand(tagsCmd) +} + +var tagsCmd = &cobra.Command{Use: "tags"} diff --git a/cmd/tags/create.go b/cmd/tags/create.go new file mode 100644 index 0000000..0e2e384 --- /dev/null +++ b/cmd/tags/create.go @@ -0,0 +1,92 @@ +package tags + +import ( + sdk "github.com/latitudesh/latitudesh-go" + "github.com/latitudesh/lsh/cmd/lsh" + "github.com/latitudesh/lsh/internal/cmdflag" + "github.com/latitudesh/lsh/internal/utils" + cobra "github.com/spf13/cobra" +) + +func NewCreateCmd() *cobra.Command { + o := CreateTagOperation{} + cmd := &cobra.Command{ + Long: "Create a Tag in the team.\n", + RunE: o.run, + PreRun: o.preRun, + Short: "Create a Tag", + Use: "create", + } + o.registerFlags(cmd) + + return cmd +} + +type CreateTagOperation struct { + BodyAttributesFlags cmdflag.Flags +} + +func (o *CreateTagOperation) registerFlags(cmd *cobra.Command) { + o.BodyAttributesFlags = cmdflag.Flags{FlagSet: cmd.Flags()} + schema := &cmdflag.FlagsSchema{ + &cmdflag.String{ + Name: "name", + Label: "Name", + Description: "Name of the Tag", + Required: true, + }, + &cmdflag.String{ + Name: "description", + Label: "Description", + Description: "Description of the Tag", + Required: false, + }, + &cmdflag.String{ + Name: "color", + Label: "Color", + Description: "Color of the Tag", + Required: true, + }, + } + + o.BodyAttributesFlags.Register(schema) +} + +func (o *CreateTagOperation) preRun(cmd *cobra.Command, args []string) { + o.BodyAttributesFlags.PreRun(cmd, args) +} + +func (o *CreateTagOperation) run(cmd *cobra.Command, args []string) error { + c := lsh.NewClient() + + attr := sdk.TagCreateAttributes{} + o.BodyAttributesFlags.AssignValues(&attr) + + createRequest := &sdk.TagCreateRequest{ + Data: sdk.TagCreateData{ + Type: "Tag", + Attributes: attr, + }, + } + + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") + return nil + } + + tag, _, err := c.Tags.Create(createRequest) + if err != nil { + utils.PrintError(err) + return err + } + + lshTag := Tag{ + Attributes: *tag, + } + + if !lsh.Debug { + utils.Render(lshTag.GetData()) + } + + return nil +} diff --git a/cmd/tags/destroy.go b/cmd/tags/destroy.go new file mode 100644 index 0000000..5817d17 --- /dev/null +++ b/cmd/tags/destroy.go @@ -0,0 +1,73 @@ +package tags + +import ( + "fmt" + "log" + "net/http" + + "github.com/latitudesh/lsh/cmd/lsh" + "github.com/latitudesh/lsh/internal/cmdflag" + "github.com/latitudesh/lsh/internal/utils" + cobra "github.com/spf13/cobra" +) + +func NewDestroyCmd() *cobra.Command { + op := DestroyTagOperation{} + cmd := &cobra.Command{ + Long: "Update a Tag in the team.\n", + RunE: op.run, + PreRun: op.preRun, + Short: "Delete Tag", + Use: "destroy", + } + op.registerFlags(cmd) + + return cmd +} + +type DestroyTagOperation struct { + PathParamFlags cmdflag.Flags +} + +func (o *DestroyTagOperation) registerFlags(cmd *cobra.Command) { + o.PathParamFlags = cmdflag.Flags{FlagSet: cmd.Flags()} + + schema := &cmdflag.FlagsSchema{ + &cmdflag.String{ + Name: "id", + Label: "ID from the Tag you want to delete", + Description: "The Tag ID", + Required: true, + }, + } + + o.PathParamFlags.Register(schema) +} + +func (o *DestroyTagOperation) preRun(cmd *cobra.Command, args []string) { + o.PathParamFlags.PreRun(cmd, args) +} + +func (o *DestroyTagOperation) run(cmd *cobra.Command, args []string) error { + c := lsh.NewClient() + + attr := struct { + ID string `json:"id"` + }{} + + o.PathParamFlags.AssignValues(&attr) + + resp, err := c.Tags.Delete(attr.ID) + if err != nil { + utils.PrintError(err) + return nil + } + + if !lsh.Debug { + if resp.StatusCode != http.StatusNoContent { + log.Fatal("Something went wrong while deleting resource.") + } + fmt.Printf("\n\nTag deleted successfully!\n\n") + } + return nil +} diff --git a/cmd/tags/list.go b/cmd/tags/list.go new file mode 100644 index 0000000..7b9c1e4 --- /dev/null +++ b/cmd/tags/list.go @@ -0,0 +1,54 @@ +package tags + +import ( + "github.com/latitudesh/lsh/cmd/lsh" + "github.com/latitudesh/lsh/internal/utils" + cobra "github.com/spf13/cobra" +) + +func NewListCmd() *cobra.Command { + op := ListTagOperation{} + cmd := &cobra.Command{ + Long: "List all Tags in the team.\n", + RunE: op.run, + Short: "List all Tags", + Use: "list", + } + + return cmd +} + +type ListTagOperation struct{} + +func (o *ListTagOperation) run(cmd *cobra.Command, args []string) error { + c := lsh.NewClient() + + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") + return nil + } + + tags, _, err := c.Tags.List(nil) + if err != nil { + utils.PrintError(err) + return err + } + + lsgTagData := []*Tag{} + for _, tag := range tags { + lshTag := Tag{ + Attributes: tag, + } + lsgTagData = append(lsgTagData, &lshTag) + } + + lshTags := Tags{ + Data: lsgTagData, + } + + if !lsh.Debug { + utils.Render(lshTags.GetData()) + } + + return nil +} diff --git a/cmd/tags/tag.go b/cmd/tags/tag.go new file mode 100644 index 0000000..38d11be --- /dev/null +++ b/cmd/tags/tag.go @@ -0,0 +1,83 @@ +package tags + +import ( + "context" + + "github.com/go-openapi/strfmt" + sdk "github.com/latitudesh/latitudesh-go" + "github.com/latitudesh/lsh/internal/output/table" + "github.com/latitudesh/lsh/internal/renderer" +) + +type Tags struct { + Data []*Tag +} + +func (m *Tags) GetData() []renderer.ResponseData { + var data []renderer.ResponseData + + for _, v := range m.Data { + data = append(data, v) + } + + return data +} + +type Tag struct { + Attributes sdk.Tag +} + +func (m *Tag) GetData() []renderer.ResponseData { + return []renderer.ResponseData{m} +} + +// Validate validates this project attributes stats +func (m *Tag) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this project attributes stats based on context it is used +func (m *Tag) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Tag) MarshalBinary() ([]byte, error) { + return []byte{}, nil +} + +// UnmarshalBinary interface implementation +func (m *Tag) UnmarshalBinary(b []byte) error { + return nil +} + +func (m *Tag) TableRow() table.Row { + attr := m.Attributes + + return table.Row{ + "id": table.Cell{ + Label: "ID", + Value: table.String(attr.ID), + }, + "name": table.Cell{ + Label: "Name", + Value: table.String(attr.Name), + }, + "description": table.Cell{ + Label: "Description", + Value: table.String(attr.Description), + }, + "slug": table.Cell{ + Label: "Slug", + Value: table.String(attr.Slug), + }, + "team": table.Cell{ + Label: "Team", + Value: table.String(attr.TeamName), + }, + "color": table.Cell{ + Label: "Color", + Value: table.String(attr.Color), + }, + } +} diff --git a/cmd/tags/update.go b/cmd/tags/update.go new file mode 100644 index 0000000..a414ee5 --- /dev/null +++ b/cmd/tags/update.go @@ -0,0 +1,117 @@ +package tags + +import ( + sdk "github.com/latitudesh/latitudesh-go" + "github.com/latitudesh/lsh/cmd/lsh" + "github.com/latitudesh/lsh/internal/cmdflag" + "github.com/latitudesh/lsh/internal/utils" + cobra "github.com/spf13/cobra" +) + +func NewUpdateCmd() *cobra.Command { + o := UpdateTagOperation{} + cmd := &cobra.Command{ + Long: "Update a Tag in the team.\n", + RunE: o.run, + PreRun: o.preRun, + Short: "Update Tag", + Use: "update", + } + o.registerFlags(cmd) + + return cmd +} + +type UpdateTagOperation struct { + PathParamFlags cmdflag.Flags + BodyAttributesFlags cmdflag.Flags +} + +func (o *UpdateTagOperation) registerFlags(cmd *cobra.Command) { + o.PathParamFlags = cmdflag.Flags{FlagSet: cmd.Flags()} + o.BodyAttributesFlags = cmdflag.Flags{FlagSet: cmd.Flags()} + + pathParamsSchema := &cmdflag.FlagsSchema{ + &cmdflag.String{ + Name: "id", + Label: "ID", + Description: "ID of the Tag", + Required: true, + }, + } + + bodyFlagsSchema := &cmdflag.FlagsSchema{ + &cmdflag.String{ + Name: "name", + Label: "Name", + Description: "Name of the Tag", + Required: false, + }, + &cmdflag.String{ + Name: "description", + Label: "Description", + Description: "Description of the Tag", + Required: false, + }, + &cmdflag.String{ + Name: "slug", + Label: "Slug", + Description: "Slug of the Tag", + Required: false, + }, + &cmdflag.String{ + Name: "color", + Label: "Color", + Description: "Color of the Tag", + Required: false, + }, + } + + o.PathParamFlags.Register(pathParamsSchema) + o.BodyAttributesFlags.Register(bodyFlagsSchema) +} + +func (o *UpdateTagOperation) preRun(cmd *cobra.Command, args []string) { + o.BodyAttributesFlags.PreRun(cmd, args) +} + +func (o *UpdateTagOperation) run(cmd *cobra.Command, args []string) error { + c := lsh.NewClient() + + pAttr := struct { + ID string `json:"id"` + }{} + o.PathParamFlags.AssignValues(&pAttr) + + bAttr := sdk.TagUpdateAttributes{} + o.BodyAttributesFlags.AssignValues(&bAttr) + + request := &sdk.TagUpdateRequest{ + Data: sdk.TagUpdateData{ + ID: pAttr.ID, + Type: "Tag", + Attributes: bAttr, + }, + } + + if lsh.DryRun { + lsh.LogDebugf("dry-run flag specified. Skip sending request.") + return nil + } + + tag, _, err := c.Tags.Update(pAttr.ID, request) + if err != nil { + utils.PrintError(err) + return err + } + + lshTag := Tag{ + Attributes: *tag, + } + + if !lsh.Debug { + utils.Render(lshTag.GetData()) + } + + return nil +} diff --git a/go.mod b/go.mod index b809af0..3e3c2f3 100755 --- a/go.mod +++ b/go.mod @@ -8,10 +8,12 @@ require ( github.com/go-openapi/strfmt v0.22.0 github.com/go-openapi/swag v0.22.7 github.com/go-openapi/validate v0.22.6 + github.com/latitudesh/latitudesh-go v0.3.2 github.com/manifoldco/promptui v0.9.0 github.com/mitchellh/go-homedir v1.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.8.0 + github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 golang.org/x/text v0.14.0 ) @@ -44,7 +46,6 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.mongodb.org/mongo-driver v1.13.1 // indirect go.opentelemetry.io/otel v1.17.0 // indirect diff --git a/go.sum b/go.sum index 143a1af..ae618fe 100755 --- a/go.sum +++ b/go.sum @@ -57,6 +57,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/latitudesh/latitudesh-go v0.3.2 h1:sF6tHMh8rEx2CdJxpWATYj1xAlOMORHTpkxYHoOapf4= +github.com/latitudesh/latitudesh-go v0.3.2/go.mod h1:ZCQD0XkY0AVl37WOfH3H16w+3AGnCfUVKcYmH1ERZpQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -172,6 +174,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/dnaeon/go-vcr.v3 v3.1.2 h1:F1smfXBqQqwpVifDfUBQG6zzaGjzT+EnVZakrOdr5wA= +gopkg.in/dnaeon/go-vcr.v3 v3.1.2/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From d9ceb07fe9c4566b77839f08d024163f22a65987 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Mon, 1 Apr 2024 20:00:04 -0300 Subject: [PATCH 27/28] fix: goreleaser --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index cf7d872..e0eb615 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,7 +12,7 @@ before: - go mod download builds: - - main: ./cmd/lsh/main.go + - env: - CGO_ENABLED=0 ldflags: From f92efa0c93e9cbaf806b7b509b25e369b6553944 Mon Sep 17 00:00:00 2001 From: Yuri Hummel Date: Wed, 3 Apr 2024 10:43:09 -0300 Subject: [PATCH 28/28] chore: Modify how doc generator builds the CLI --- .github/workflows/release.yml | 1 + internal/generator/documentation/generate.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c99174..73530e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }} generate-docs: + runs-on: ubuntu-latest steps: - name: Set up Go diff --git a/internal/generator/documentation/generate.go b/internal/generator/documentation/generate.go index 57c41b9..1b89cb5 100644 --- a/internal/generator/documentation/generate.go +++ b/internal/generator/documentation/generate.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "github.com/latitudesh/lsh/cli" + "github.com/latitudesh/lsh/cmd" "github.com/spf13/cobra" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -25,7 +25,7 @@ var cmdSelection = map[string]int{ } func main() { - rootCmd, err := cli.MakeRootCmd() + rootCmd, err := cmd.Execute() if err != nil { log.Fatal("Cmd construction error: ", err) }