Skip to content

Commit

Permalink
make --json and --yaml global flags
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Sep 2, 2020
1 parent 9ce0ac0 commit 2774969
Show file tree
Hide file tree
Showing 23 changed files with 4 additions and 56 deletions.
2 changes: 0 additions & 2 deletions cmd/check_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_ssh-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/create_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 0 additions & 3 deletions cmd/retrieve_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
5 changes: 0 additions & 5 deletions cmd/retrieve_facilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_hardware_reservations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 0 additions & 3 deletions cmd/retrieve_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
5 changes: 0 additions & 5 deletions cmd/retrieve_operating_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
5 changes: 0 additions & 5 deletions cmd/retrieve_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions cmd/retrieve_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 0 additions & 3 deletions cmd/retrieve_vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2774969

Please sign in to comment.