From 2774969f25ebb0c9b08746fd051216bf89cb930b Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Sat, 29 Aug 2020 16:58:22 -0400 Subject: [PATCH] make --json and --yaml global flags Signed-off-by: Marques Johansson --- cmd/check_capacity.go | 2 -- cmd/create_device.go | 2 -- cmd/create_organization.go | 2 -- cmd/create_project.go | 2 -- cmd/create_ssh-key.go | 2 -- cmd/create_virtual_network.go | 2 -- cmd/create_volume.go | 2 -- cmd/retrieve_capacity.go | 2 -- cmd/retrieve_device.go | 2 -- cmd/retrieve_event.go | 3 --- cmd/retrieve_facilities.go | 5 ----- cmd/retrieve_hardware_reservations.go | 2 -- cmd/retrieve_ip.go | 3 --- cmd/retrieve_operating_system.go | 5 ----- cmd/retrieve_organization.go | 2 -- cmd/retrieve_plans.go | 5 ----- cmd/retrieve_project.go | 2 -- cmd/retrieve_ssh_key.go | 2 -- cmd/retrieve_user.go | 2 -- cmd/retrieve_virtual_network.go | 2 -- cmd/retrieve_volume.go | 2 -- cmd/retrieve_vpn.go | 3 --- cmd/root.go | 4 ++++ 23 files changed, 4 insertions(+), 56 deletions(-) diff --git a/cmd/check_capacity.go b/cmd/check_capacity.go index 9a3777f2..1de88a35 100644 --- a/cmd/check_capacity.go +++ b/cmd/check_capacity.go @@ -70,6 +70,4 @@ func init() { _ = checkCapacityCommand.MarkFlagRequired("facility") _ = checkCapacityCommand.MarkFlagRequired("plan") _ = checkCapacityCommand.MarkFlagRequired("quantity") - checkCapacityCommand.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - checkCapacityCommand.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_device.go b/cmd/create_device.go index 3ec2147d..e0ffd7a3 100644 --- a/cmd/create_device.go +++ b/cmd/create_device.go @@ -151,6 +151,4 @@ func init() { createDeviceCmd.Flags().BoolVarP(&spotInstance, "spot-instance", "I", false, `Set the device as a spot instance`) createDeviceCmd.Flags().Float64VarP(&spotPriceMax, "spot-price-max", "m", 0, `--spot-price-max=1.2 or -m=1.2`) createDeviceCmd.Flags().StringVarP(&terminationTime, "termination-time", "T", "", `Device termination time: --termination-time="15:04:05"`) - createDeviceCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createDeviceCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_organization.go b/cmd/create_organization.go index a3ecac73..9066d2f4 100644 --- a/cmd/create_organization.go +++ b/cmd/create_organization.go @@ -80,6 +80,4 @@ func init() { createOrganizationCmd.Flags().StringVarP(&logo, "logo", "l", "", "Logo URL]") _ = createOrganizationCmd.MarkFlagRequired("name") - createOrganizationCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createOrganizationCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_project.go b/cmd/create_project.go index e3006d26..a60a84ff 100644 --- a/cmd/create_project.go +++ b/cmd/create_project.go @@ -72,6 +72,4 @@ func init() { createProjectCmd.Flags().StringVarP(&paymentMethodID, "payment-method-id", "m", "", "UUID of the payment method") _ = createProjectCmd.MarkFlagRequired("name") - createProjectCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createProjectCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_ssh-key.go b/cmd/create_ssh-key.go index 9013a5da..9c210520 100644 --- a/cmd/create_ssh-key.go +++ b/cmd/create_ssh-key.go @@ -65,6 +65,4 @@ func init() { _ = createSSHKeyCmd.MarkFlagRequired("label") _ = createSSHKeyCmd.MarkFlagRequired("key") - createSSHKeyCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createSSHKeyCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_virtual_network.go b/cmd/create_virtual_network.go index e27430df..7489b7af 100644 --- a/cmd/create_virtual_network.go +++ b/cmd/create_virtual_network.go @@ -68,6 +68,4 @@ func init() { _ = createVirtualNetworkCmd.MarkFlagRequired("project-id") _ = createVirtualNetworkCmd.MarkFlagRequired("facility") - createVirtualNetworkCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createVirtualNetworkCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/create_volume.go b/cmd/create_volume.go index 7ede28e3..7efddf1b 100644 --- a/cmd/create_volume.go +++ b/cmd/create_volume.go @@ -83,6 +83,4 @@ func init() { createVolumeCmd.Flags().StringVarP(&billingCycle, "billing-cycle", "b", "hourly", "Billing cycle") createVolumeCmd.Flags().StringVarP(&description, "description", "d", "", "Description of the volume") createVolumeCmd.Flags().BoolVarP(&locked, "locked", "l", false, "Set the volume to be locked") - createVolumeCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - createVolumeCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_capacity.go b/cmd/retrieve_capacity.go index 6640d024..ebd71af8 100644 --- a/cmd/retrieve_capacity.go +++ b/cmd/retrieve_capacity.go @@ -57,6 +57,4 @@ packet capacity get func init() { capacityCmd.AddCommand(retrieveCapacityCmd) - retrieveCapacityCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveCapacityCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_device.go b/cmd/retrieve_device.go index 67712936..ce9370c8 100644 --- a/cmd/retrieve_device.go +++ b/cmd/retrieve_device.go @@ -77,6 +77,4 @@ packet device get --id [device_UUID] func init() { retriveDeviceCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") retriveDeviceCmd.Flags().StringVarP(&deviceID, "id", "i", "", "UUID of the device") - retriveDeviceCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retriveDeviceCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_event.go b/cmd/retrieve_event.go index 275a1eeb..56bc00be 100644 --- a/cmd/retrieve_event.go +++ b/cmd/retrieve_event.go @@ -109,7 +109,4 @@ func init() { retrieveEventCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") retrieveEventCmd.Flags().StringVarP(&deviceID, "device-id", "d", "", "UUID of the device") retrieveEventCmd.Flags().StringVarP(&volumeID, "organization-id", "o", "", "UUID of the organization") - - retrieveEventCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveEventCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_facilities.go b/cmd/retrieve_facilities.go index 2604a396..d51592fa 100644 --- a/cmd/retrieve_facilities.go +++ b/cmd/retrieve_facilities.go @@ -51,8 +51,3 @@ packet facilities get return output(facilities, header, &data) }, } - -func init() { - retrieveFacilitiesCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "-j or --json JSON output") - retrieveFacilitiesCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "-y or --yaml YAML output") -} diff --git a/cmd/retrieve_hardware_reservations.go b/cmd/retrieve_hardware_reservations.go index 58e5fce3..4b670187 100644 --- a/cmd/retrieve_hardware_reservations.go +++ b/cmd/retrieve_hardware_reservations.go @@ -79,6 +79,4 @@ func init() { hardwareReservationsCmd.AddCommand(retrieveHardwareReservationsCmd) retrieveHardwareReservationsCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") retrieveHardwareReservationsCmd.Flags().StringVarP(&hardwareReservationID, "id", "i", "", "UUID of the hardware reservation") - retrieveHardwareReservationsCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveHardwareReservationsCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_ip.go b/cmd/retrieve_ip.go index f8e2c387..eca56802 100644 --- a/cmd/retrieve_ip.go +++ b/cmd/retrieve_ip.go @@ -106,7 +106,4 @@ func init() { retrieveIPCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") retrieveIPCmd.Flags().StringVarP(&assignmentID, "assignment-id", "a", "", "UUID of the assignment") retrieveIPCmd.Flags().StringVarP(&reservationID, "reservation-id", "r", "", "UUID of the reservation") - - retrieveIPCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveIPCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_operating_system.go b/cmd/retrieve_operating_system.go index 9dbfa415..47daf153 100644 --- a/cmd/retrieve_operating_system.go +++ b/cmd/retrieve_operating_system.go @@ -47,8 +47,3 @@ var retrieveOperatingSystemCmd = &cobra.Command{ return output(oss, header, &data) }, } - -func init() { - retrieveOperatingSystemCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveOperatingSystemCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") -} diff --git a/cmd/retrieve_organization.go b/cmd/retrieve_organization.go index aa76024a..3fd6ebbb 100644 --- a/cmd/retrieve_organization.go +++ b/cmd/retrieve_organization.go @@ -71,6 +71,4 @@ packet organization get -i [organization-id] func init() { retrieveOrganizationCmd.Flags().StringVarP(&organizationID, "organization-id", "i", "", "UUID of the organization") - retrieveOrganizationCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveOrganizationCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_plans.go b/cmd/retrieve_plans.go index 840eca5e..ff68aa09 100644 --- a/cmd/retrieve_plans.go +++ b/cmd/retrieve_plans.go @@ -50,8 +50,3 @@ var retrievePlansCmd = &cobra.Command{ return output(plans, header, &data) }, } - -func init() { - retrievePlansCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrievePlansCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") -} diff --git a/cmd/retrieve_project.go b/cmd/retrieve_project.go index 4b345b97..923a44e8 100644 --- a/cmd/retrieve_project.go +++ b/cmd/retrieve_project.go @@ -94,6 +94,4 @@ packet project get -n [project_name] func init() { retriveProjectCmd.Flags().StringVarP(&projectName, "project", "n", "", "Name of the project") retriveProjectCmd.Flags().StringVarP(&projectID, "project-id", "i", "", "UUID of the project") - retriveProjectCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retriveProjectCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_ssh_key.go b/cmd/retrieve_ssh_key.go index ead02e2e..54b6e023 100644 --- a/cmd/retrieve_ssh_key.go +++ b/cmd/retrieve_ssh_key.go @@ -75,6 +75,4 @@ packet ssh-key get --id [ssh-key_UUID] func init() { retrieveSSHKeysCmd.Flags().StringVarP(&sshKeyID, "id", "i", "", "UUID of the SSH key") - retrieveSSHKeysCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveSSHKeysCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_user.go b/cmd/retrieve_user.go index c16f96b3..7b210b4c 100644 --- a/cmd/retrieve_user.go +++ b/cmd/retrieve_user.go @@ -69,6 +69,4 @@ packet user get --id [user_UUID] func init() { retriveUserCmd.Flags().StringVarP(&userID, "id", "i", "", "UUID of the user") - retriveUserCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retriveUserCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_virtual_network.go b/cmd/retrieve_virtual_network.go index fd98b09b..b3d16735 100644 --- a/cmd/retrieve_virtual_network.go +++ b/cmd/retrieve_virtual_network.go @@ -56,6 +56,4 @@ packet virtual-network get -p [project_UUID] func init() { retrieveVirtualNetworksCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") _ = retrieveVirtualNetworksCmd.MarkFlagRequired("project-id") - retrieveVirtualNetworksCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveVirtualNetworksCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_volume.go b/cmd/retrieve_volume.go index bccc0613..008f56b5 100644 --- a/cmd/retrieve_volume.go +++ b/cmd/retrieve_volume.go @@ -83,6 +83,4 @@ packet volume get --id [volume_UUID] func init() { retriveVolumeCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "UUID of the project") retriveVolumeCmd.Flags().StringVarP(&volumeID, "id", "i", "", "UUID of the volume") - retriveVolumeCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retriveVolumeCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/retrieve_vpn.go b/cmd/retrieve_vpn.go index 7929be62..5daae121 100644 --- a/cmd/retrieve_vpn.go +++ b/cmd/retrieve_vpn.go @@ -51,7 +51,4 @@ packet vpn get --faciliy ewr1 func init() { retrieveVpnCmd.Flags().StringVarP(&facility, "facility", "f", "", "Code of the facility for which VPN config is to be retrieved") _ = retrieveVpnCmd.MarkFlagRequired("id") - - retrieveVpnCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") - retrieveVpnCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") } diff --git a/cmd/root.go b/cmd/root.go index 6cd28eef..f8a6c0f4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,6 +74,10 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Path to JSON or YAML configuration file") + + rootCmd.PersistentFlags().BoolVarP(&isJSON, "json", "j", false, "JSON output") + rootCmd.PersistentFlags().BoolVarP(&isYaml, "yaml", "y", false, "YAML output") + rootCmd.Version = Version }