Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Idea] [Breaking changes!] Add shorthand flags #171

Merged
merged 7 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions args_short.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
Copyright 2016 The Doctl Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package doctl

const (
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this large block of commented out code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My assumption was some placeholder in case we want to introduce more short flags for other things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanzhong @aybabtme I left it for placeholder, but I removed it. For now I defined it for force action, but we can add more actions later.

// ArgActionID is an action id argument.
ArgActionID = "action-id"
// ArgActionAfter is an action after argument.
ArgActionAfter = "after"
// ArgActionBefore is an action before argument.
ArgActionBefore = "before"
// ArgActionResourceType is an action resource type argument.
ArgActionResourceType = "resource-type"
// ArgActionRegion is an action region argument.
ArgActionRegion = "region"
// ArgActionStatus is an action status argument.
ArgActionStatus = "status"
// ArgActionType is an action type argument.
ArgActionType = "action-type"
// ArgCommandWait is a wait for a droplet to be created argument.
ArgCommandWait = "wait"
// ArgDomainName is a domain name argument.
ArgDomainName = "domain-name"
// ArgDropletID is a droplet id argument.
ArgDropletID = "droplet-id"
// ArgKernelID is a ekrnel id argument.
ArgKernelID = "kernel-id"
// ArgImage is an image argument.
ArgImage = "image"
// ArgImageID is an image id argument.
ArgImageID = "image-id"
// ArgImagePublic is a public image argument.
ArgImagePublic = "public"
// ArgImageSlug is an image slug argment.
ArgImageSlug = "image-slug"
// ArgIPAddress is an IP address argument.
ArgIPAddress = "ip-address"
// ArgDropletName is a droplet name argument.
ArgDropletName = "droplet-name"
// ArgResizeDisk is a resize disk argument.
ArgResizeDisk = "resize-disk"
// ArgSnapshotName is a snapshot name arugment.
ArgSnapshotName = "snapshot-name"
// ArgBackups is an enable backups argument.
ArgBackups = "enable-backups"
// ArgIPv6 is an enable IPv6 argument.
ArgIPv6 = "enable-ipv6"
// ArgPrivateNetworking is an enable private networking argument.
ArgPrivateNetworking = "enable-private-networking"
// ArgRecordData is a record data argument.
ArgRecordData = "record-data"
// ArgRecordID is a record id argument.
ArgRecordID = "record-id"
// ArgRecordName is a record name argument.
ArgRecordName = "record-name"
// ArgRecordPort is a record port argument.
ArgRecordPort = "record-port"
// ArgRecordPriority is a record priority argument.
ArgRecordPriority = "record-priority"
// ArgRecordType is a record type argument.
ArgRecordType = "record-type"
// ArgRecordWeight is a record weight argument.
ArgRecordWeight = "record-weight"
// ArgRegionSlug is a region slug argument.
ArgRegionSlug = "region"
// ArgSizeSlug is a size slug argument.
ArgSizeSlug = "size"
// ArgsSSHKeyPath is a ssh argument.
ArgsSSHKeyPath = "ssh-key-path"
// ArgSSHKeys is a ssh key argument.
ArgSSHKeys = "ssh-keys"
// ArgsSSHPort is a ssh argument.
ArgsSSHPort = "ssh-port"
// ArgsSSHAgentForwarding is a ssh argument.
ArgsSSHAgentForwarding = "ssh-agent-forwarding"
// ArgsSSHPrivateIP is a ssh argument.
ArgsSSHPrivateIP = "ssh-private-ip"
// ArgUserData is a user data argument.
ArgUserData = "user-data"
// ArgUserDataFile is a user data file location argument.
ArgUserDataFile = "user-data-file"
// ArgImageName name is an image name argument.
ArgImageName = "image-name"
// ArgKey is a key argument.
ArgKey = "key"
// ArgKeyName is a key name argument.
ArgKeyName = "key-name"
// ArgKeyPublicKey is a public key argument.
ArgKeyPublicKey = "public-key"
// ArgKeyPublicKeyFile is a public key file argument.
ArgKeyPublicKeyFile = "public-key-file"
// ArgSSHUser is a SSH user argument.
ArgSSHUser = "ssh-user"
// ArgFormat is columns to include in output argment.
ArgFormat = "format"
// ArgNoHeader hides the output header.
ArgNoHeader = "no-header"
// ArgPollTime is how long before the next poll argument.
ArgPollTime = "poll-timeout"
// ArgTagName is a tag name
ArgTagName = "tag-name"
// ArgTagNames is a slice of possible tag names
ArgTagNames = "tag-names"
//ArgTemplate is template format
ArgTemplate = "template"

// ArgOutput is an output type argument.
ArgOutput = "output"

// ArgVolumeSize is the size of a volume.
ArgVolumeSize = "size"
// ArgVolumeDesc is the description of a volume.
ArgVolumeDesc = "desc"
// ArgVolumeRegion is the region of a volume.
ArgVolumeRegion = "region"
// ArgVolumeList is the IDs of many volumes.
ArgVolumeList = "volumes"
*/
// ArgDeleteForce forces deletion actions
ArgShortDeleteForce = "f"

// ArgResourceType is the resource type for snapshot.
//ArgShortResourceType = "resource"
)
14 changes: 7 additions & 7 deletions commands/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ func Actions() *Command {

cmdActionList := CmdBuilder(cmd, RunCmdActionList, "list", "list actions", Writer,
aliasOpt("ls"), displayerType(&action{}), docCategories("action"))
AddStringFlag(cmdActionList, doctl.ArgActionResourceType, "", "Action resource type")
AddStringFlag(cmdActionList, doctl.ArgActionRegion, "", "Action region")
AddStringFlag(cmdActionList, doctl.ArgActionAfter, "", "Action completed after in RFC3339 format")
AddStringFlag(cmdActionList, doctl.ArgActionBefore, "", "Action completed before in RFC3339 format")
AddStringFlag(cmdActionList, doctl.ArgActionStatus, "", "Action status")
AddStringFlag(cmdActionList, doctl.ArgActionType, "", "Action type")
AddStringFlag(cmdActionList, doctl.ArgActionResourceType, "", "", "Action resource type")
AddStringFlag(cmdActionList, doctl.ArgActionRegion, "", "", "Action region")
AddStringFlag(cmdActionList, doctl.ArgActionAfter, "", "", "Action completed after in RFC3339 format")
AddStringFlag(cmdActionList, doctl.ArgActionBefore, "", "", "Action completed before in RFC3339 format")
AddStringFlag(cmdActionList, doctl.ArgActionStatus, "", "", "Action status")
AddStringFlag(cmdActionList, doctl.ArgActionType, "", "", "Action type")

cmdActionWait := CmdBuilder(cmd, RunCmdActionWait, "wait ACTIONID", "wait for action to complete", Writer,
aliasOpt("w"), displayerType(&action{}), docCategories("action"))
AddIntFlag(cmdActionWait, doctl.ArgPollTime, 5, "Re-poll time in seconds")
AddIntFlag(cmdActionWait, doctl.ArgPollTime, "", 5, "Re-poll time in seconds")

return cmd
}
Expand Down
20 changes: 10 additions & 10 deletions commands/doit.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ func isBeta() bool {
}

// AddStringFlag adds a string flag to a command.
func AddStringFlag(cmd *Command, name, dflt, desc string, opts ...flagOpt) {
func AddStringFlag(cmd *Command, name, shorthand, dflt, desc string, opts ...flagOpt) {
fn := flagName(cmd, name)
cmd.Flags().String(name, dflt, desc)
cmd.Flags().StringP(name, shorthand, dflt, desc)

for _, o := range opts {
o(cmd, name, fn)
Expand All @@ -225,9 +225,9 @@ func AddStringFlag(cmd *Command, name, dflt, desc string, opts ...flagOpt) {
}

// AddIntFlag adds an integr flag to a command.
func AddIntFlag(cmd *Command, name string, def int, desc string, opts ...flagOpt) {
func AddIntFlag(cmd *Command, name, shorthand string, def int, desc string, opts ...flagOpt) {
fn := flagName(cmd, name)
cmd.Flags().Int(name, def, desc)
cmd.Flags().IntP(name, shorthand, def, desc)
viper.BindPFlag(fn, cmd.Flags().Lookup(name))

for _, o := range opts {
Expand All @@ -236,9 +236,9 @@ func AddIntFlag(cmd *Command, name string, def int, desc string, opts ...flagOpt
}

// AddBoolFlag adds a boolean flag to a command.
func AddBoolFlag(cmd *Command, name string, def bool, desc string, opts ...flagOpt) {
func AddBoolFlag(cmd *Command, name, shorthand string, def bool, desc string, opts ...flagOpt) {
fn := flagName(cmd, name)
cmd.Flags().Bool(name, def, desc)
cmd.Flags().BoolP(name, shorthand, def, desc)
viper.BindPFlag(fn, cmd.Flags().Lookup(name))

for _, o := range opts {
Expand All @@ -247,9 +247,9 @@ func AddBoolFlag(cmd *Command, name string, def bool, desc string, opts ...flagO
}

// AddStringSliceFlag adds a string slice flag to a command.
func AddStringSliceFlag(cmd *Command, name string, def []string, desc string, opts ...flagOpt) {
func AddStringSliceFlag(cmd *Command, name, shorthand string, def []string, desc string, opts ...flagOpt) {
fn := flagName(cmd, name)
cmd.Flags().StringSlice(name, def, desc)
cmd.Flags().StringSliceP(name, shorthand, def, desc)
viper.BindPFlag(fn, cmd.Flags().Lookup(name))

for _, o := range opts {
Expand Down Expand Up @@ -401,8 +401,8 @@ func cmdBuilderWithInit(parent *Command, cr CmdRunner, cliText, desc string, out
if cols := c.fmtCols; cols != nil {
formatHelp := fmt.Sprintf("Columns for output in a comma seperated list. Possible values: %s",
strings.Join(cols, ","))
AddStringFlag(c, doctl.ArgFormat, "", formatHelp)
AddBoolFlag(c, doctl.ArgNoHeader, false, "hide headers")
AddStringFlag(c, doctl.ArgFormat, "", "", formatHelp)
AddBoolFlag(c, doctl.ArgNoHeader, "", false, "hide headers")
}

return c
Expand Down
32 changes: 16 additions & 16 deletions commands/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func Domain() *Command {

cmdDomainCreate := CmdBuilder(cmd, RunDomainCreate, "create <domain>", "create domain", Writer,
aliasOpt("c"), displayerType(&domain{}), docCategories("domain"))
AddStringFlag(cmdDomainCreate, doctl.ArgIPAddress, "", "IP address", requiredOpt())

AddStringFlag(cmdDomainCreate, doctl.ArgIPAddress, "", "", "IP address", requiredOpt())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpick, extra whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanzhong fixed. :D I hope it's correct now. Also fixed indentation for volumes.go at one point.
And yea, commit should be formatting but whatever. :P

CmdBuilder(cmd, RunDomainList, "list", "list domains", Writer,
aliasOpt("ls"), displayerType(&domain{}), docCategories("domain"))

Expand All @@ -59,29 +59,29 @@ func Domain() *Command {

cmdRecordList := CmdBuilder(cmdRecord, RunRecordList, "list <domain>", "list records", Writer,
aliasOpt("ls"), displayerType(&domainRecord{}), docCategories("domain"))
AddStringFlag(cmdRecordList, doctl.ArgDomainName, "", "Domain name")
AddStringFlag(cmdRecordList, doctl.ArgDomainName, "", "", "Domain name")

cmdRecordCreate := CmdBuilder(cmdRecord, RunRecordCreate, "create <domain>", "create record", Writer,
aliasOpt("c"), displayerType(&domainRecord{}), docCategories("domain"))
AddStringFlag(cmdRecordCreate, doctl.ArgRecordType, "", "Record type")
AddStringFlag(cmdRecordCreate, doctl.ArgRecordName, "", "Record name")
AddStringFlag(cmdRecordCreate, doctl.ArgRecordData, "", "Record data")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordPriority, 0, "Record priority")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordPort, 0, "Record port")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordWeight, 0, "Record weight")
AddStringFlag(cmdRecordCreate, doctl.ArgRecordType, "", "", "Record type")
AddStringFlag(cmdRecordCreate, doctl.ArgRecordName, "", "", "Record name")
AddStringFlag(cmdRecordCreate, doctl.ArgRecordData, "", "", "Record data")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordPriority, "", 0, "Record priority")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordPort, "", 0, "Record port")
AddIntFlag(cmdRecordCreate, doctl.ArgRecordWeight, "", 0, "Record weight")

CmdBuilder(cmdRecord, RunRecordDelete, "delete <domain> <record id...>", "delete record", Writer,
aliasOpt("d"), docCategories("domain"))

cmdRecordUpdate := CmdBuilder(cmdRecord, RunRecordUpdate, "update <domain>", "update record", Writer,
aliasOpt("u"), displayerType(&domainRecord{}), docCategories("domain"))
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordID, 0, "Record ID")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordType, "", "Record type")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordName, "", "Record name")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordData, "", "Record data")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordPriority, 0, "Record priority")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordPort, 0, "Record port")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordWeight, 0, "Record weight")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordID, "", 0, "Record ID")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordType, "", "", "Record type")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordName, "", "", "Record name")
AddStringFlag(cmdRecordUpdate, doctl.ArgRecordData, "", "", "Record data")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordPriority, "", 0, "Record priority")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordPort, "", 0, "Record port")
AddIntFlag(cmdRecordUpdate, doctl.ArgRecordWeight, "", 0, "Record weight")

return cmd
}
Expand Down
Loading