Skip to content

Commit

Permalink
Merge branch 'flags-refactor' into 'develop'
Browse files Browse the repository at this point in the history
Refactor "flags" package to "flagsets"

See merge request open-source/bytemark-client!300
  • Loading branch information
Hannah Pirie committed Dec 6, 2018
2 parents 640dcc6 + 6160d5a commit a465e94
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions HACKING
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ Here's a tree of the folders in this repo with descriptions of what each is for
│   │ │ arguments into flags
│   │   ├── auth - Authentication routine for the client, called via
│   │ │ with.EnsureAuth
│   │   ├── flags - common flags & code to support reading complex objects
│   │ │ from them. e.g. VirtualMachineSpec & ImageInstall
│   │   ├── flagsets - common flags & code to support reading complex objects
│   │ │ from them. e.g. VirtualMachineSpec & ImageInstall
│   │ ├── wait - functions which wait for a condition to be true before
│   │ │ returning
│   │   └── with - functions for chaining together using app.Action to
Expand Down Expand Up @@ -225,4 +225,4 @@ To generate the hash, use the following command.

find . -type d \! -path './.*' \! -path './vendor/*' | sort | shasum -a 256

# sha256sum: 13111e01c90d466eae6d7c1c4f53d031e6274a988e0f2861b0be27d958988647
# sha256sum: 4c172559ebbe8e0e565de3dd72236d56bb85bbed9271249804b22dcef3a006d1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flags
package flagsets

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flags
package flagsets

import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flags
package flagsets

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/commands/add/disc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package add
import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
"github.com/BytemarkHosting/bytemark-client/util/log"
Expand All @@ -20,7 +20,7 @@ func init() {
Usage: "A disc to add. You can specify as many discs as you like by adding more --disc flags.",
Value: new(util.DiscSpecFlag),
},
flags.Force,
flagsets.Force,
cli.GenericFlag{
Name: "server",
Usage: "the server to add the disc to",
Expand Down
6 changes: 3 additions & 3 deletions cmd/bytemark/commands/add/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/cliutil"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
Expand Down Expand Up @@ -40,7 +40,7 @@ See the price list for more details at http://www.bytemark.co.uk/prices
If --hwprofile-locked is set then the cloud server's virtual hardware won't be changed over time.`,
Flags: cliutil.ConcatFlags(app.OutputFlags("server", "object"),
flags.ServerSpecFlags, flags.ImageInstallFlags, flags.ImageInstallAuthFlags,
flagsets.ServerSpecFlags, flagsets.ImageInstallFlags, flagsets.ImageInstallAuthFlags,
[]cli.Flag{
cli.GenericFlag{
Name: "name",
Expand All @@ -61,7 +61,7 @@ If --hwprofile-locked is set then the cloud server's virtual hardware won't be c
// createServer creates a server objec to be created by the brain and sends it.
func createServer(c *app.Context) (err error) {
name := c.VirtualMachineName("name")
spec, err := flags.PrepareServerSpec(c, true)
spec, err := flagsets.PrepareServerSpec(c, true)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/bytemark/commands/admin/add/vm_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package add
import (
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/cliutil"
"github.com/BytemarkHosting/bytemark-client/lib/brain"
Expand All @@ -29,7 +29,7 @@ Multiple --disc flags can be used to add multiple discs to the VM Default
If --backup is set then a backup of the first disk will be taken at the
frequency specified - never, daily, weekly or monthly. If not specified the backup will default to weekly.`,
Flags: cliutil.ConcatFlags(app.OutputFlags("vm default", "object"),
flags.ImageInstallFlags, flags.ServerSpecFlags,
flagsets.ImageInstallFlags, flagsets.ServerSpecFlags,
[]cli.Flag{
cli.StringFlag{
Name: "default-name",
Expand All @@ -54,7 +54,7 @@ frequency specified - never, daily, weekly or monthly. If not specified the back
if err != nil {
return
}
spec, err := flags.PrepareServerSpec(c, false)
spec, err := flagsets.PrepareServerSpec(c, false)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/bytemark/commands/delete/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
"github.com/BytemarkHosting/bytemark-client/lib"
Expand All @@ -30,7 +30,7 @@ If --recursive is specified, all servers in the group will be purged. Otherwise,
Usage: "the name of the group to delete",
Value: new(app.GroupNameFlag),
},
flags.Force,
flagsets.Force,
},
Action: app.Action(args.Optional("group"), with.RequiredFlags("group"), with.Group("group"), func(ctx *app.Context) (err error) {
recursive := ctx.Bool("recursive")
Expand Down
6 changes: 3 additions & 3 deletions cmd/bytemark/commands/update/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/config"
"github.com/BytemarkHosting/bytemark-client/lib"
Expand Down Expand Up @@ -179,7 +179,7 @@ func init() {
Description: `Manipulate the bytemark-client configuration
Available variables:` + config.VarsDescription,
Flags: append(configVariables.configFlags(), flags.Force),
Flags: append(configVariables.configFlags(), flagsets.Force),
Action: app.Action(configVariables.updateConfig),
})
}
Expand All @@ -196,7 +196,7 @@ func (variables configVars) updateConfig(c *app.Context) error {
if set != "" && unset {
return c.Help("cannot set and unset " + variable.name)
}
if set != "" && !flags.Forced(c) && variable.validate != nil {
if set != "" && !flagsets.Forced(c) && variable.validate != nil {
if variable.needAuth && !withAuth {
err := with.Auth(c)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/bytemark/commands/update/disc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
brainRequests "github.com/BytemarkHosting/bytemark-client/lib/requests/brain"
Expand All @@ -25,7 +25,7 @@ Resizes the given disc to the given size. Sizes may be specified with a + in fro
Moving the disc to another server may require you to update your operating system configuration. Both servers must be shutdown and root discs cannot be moved. Please find documentation for moving discs at https://docs.bytemark.co.uk/article/moving-a-disc`,
Flags: []cli.Flag{
flags.Force,
flagsets.Force,
cli.StringFlag{
Name: "disc",
Usage: "the disc to resize",
Expand Down Expand Up @@ -78,7 +78,7 @@ func resizeDisc(c *app.Context) (err error) {

log.Logf("Resizing %s from %dGiB to %dGiB...", c.Disc.Label, c.Disc.Size/1024, newSize/1024)

if !flags.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("Are you certain you wish to perform this resize?")) {
if !flagsets.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("Are you certain you wish to perform this resize?")) {
return util.UserRequestedExit{}
}

Expand All @@ -97,7 +97,7 @@ func moveDisc(c *app.Context) (err error) {

log.Logf("This may require an update to the operating system configuration, please find documentation for moving discs at https://docs.bytemark.co.uk/article/moving-a-disc\r\n")

if !flags.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("Are you certain you wish to move the disc?")) {
if !flagsets.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("Are you certain you wish to move the disc?")) {
return util.UserRequestedExit{}
}
log.Logf("Moving %s from %s to %s...", c.Disc.Label, vmName, newVM)
Expand Down
8 changes: 4 additions & 4 deletions cmd/bytemark/commands/update/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
Expand Down Expand Up @@ -44,7 +44,7 @@ EXAMPLES
bytemark update server --new-name rennes.bretagne.france charata.chaco.argentina
This will move the server called charata in the chaco group in the argentina account, placing it in the bretagne group in the france account and rename it to rennes.`,
Flags: append(app.OutputFlags("server", "object"),
flags.Force,
flagsets.Force,
cli.GenericFlag{
Name: "memory",
Value: new(util.SizeSpecFlag),
Expand Down Expand Up @@ -97,7 +97,7 @@ func updateMemory(c *app.Context) error {
return nil
}
if c.VirtualMachine.Memory < memory {
if !flags.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("You're increasing the memory by %dGiB - this may cost more, are you sure?", (memory-c.VirtualMachine.Memory)/1024)) {
if !flagsets.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("You're increasing the memory by %dGiB - this may cost more, are you sure?", (memory-c.VirtualMachine.Memory)/1024)) {
return util.UserRequestedExit{}
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func updateCores(c *app.Context) error {
return nil
}
if c.VirtualMachine.Cores < cores {
if !flags.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("You are increasing the number of cores from %d to %d. This may cause your VM to cost more, are you sure?", c.VirtualMachine.Cores, cores)) {
if !flagsets.Forced(c) && !util.PromptYesNo(c.Prompter(), fmt.Sprintf("You are increasing the number of cores from %d to %d. This may cause your VM to cost more, are you sure?", c.VirtualMachine.Cores, cores)) {
return util.UserRequestedExit{}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/bytemark/reimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flags"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/flagsets"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/cliutil"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/util"
Expand Down Expand Up @@ -34,7 +34,7 @@ The root password will be output on stdout if the imaging succeeded, otherwise n
Specify --force to prevent prompting.
The root password will be output on stdout if the imaging succeeded, otherwise nothing will (and the exit code will be nonzero)`,
Flags: cliutil.ConcatFlags(flags.ImageInstallFlags, flags.ImageInstallAuthFlags,
Flags: cliutil.ConcatFlags(flagsets.ImageInstallFlags, flagsets.ImageInstallAuthFlags,
[]cli.Flag{
forceFlag, cli.GenericFlag{
Name: "server",
Expand All @@ -44,7 +44,7 @@ The root password will be output on stdout if the imaging succeeded, otherwise n
}),
Action: app.Action(args.Optional("server"), with.RequiredFlags("server"), with.Auth, func(c *app.Context) (err error) {
vmName := c.VirtualMachineName("server")
imageInstall, defaulted, err := flags.PrepareImageInstall(c, true)
imageInstall, defaulted, err := flagsets.PrepareImageInstall(c, true)
if err != nil {
return
}
Expand Down

0 comments on commit a465e94

Please sign in to comment.