Modernize usage of urfave/cli

This commit is contained in:
Noah 2020-06-04 23:11:03 -07:00
parent de896c93e6
commit eae7258ce1
7 changed files with 64 additions and 58 deletions

View File

@ -22,25 +22,27 @@ import (
// Convert between image files (png or bitmap) and Doodle drawing files (levels
// and doodads)
var Convert cli.Command
var Convert *cli.Command
func init() {
Convert = cli.Command{
Convert = &cli.Command{
Name: "convert",
Usage: "convert between images and Doodle drawing files",
ArgsUsage: "<input> <output>",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "key",
Usage: "chroma key color for transparency on input image files",
Value: "#ffffff",
},
cli.StringFlag{
Name: "title, t",
&cli.StringFlag{
Name: "title",
Aliases: []string{"t"},
Usage: "set the title of the level or doodad being created",
},
cli.StringFlag{
Name: "palette, p",
&cli.StringFlag{
Name: "palette",
Aliases: []string{"p"},
Usage: "use a palette JSON to define color swatch properties",
},
},
@ -63,7 +65,7 @@ func init() {
)
}
args := c.Args()
args := c.Args().Slice()
var (
inputFiles = args[:len(args)-1]
inputType = strings.ToLower(filepath.Ext(inputFiles[0]))

View File

@ -11,43 +11,43 @@ import (
)
// EditDoodad allows writing doodad metadata.
var EditDoodad cli.Command
var EditDoodad *cli.Command
func init() {
EditDoodad = cli.Command{
EditDoodad = &cli.Command{
Name: "edit-doodad",
Usage: "update metadata for a Doodad file",
ArgsUsage: "<filename.doodad>",
Flags: []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "quiet, q",
Usage: "limit output (don't show doodad data at the end)",
},
cli.StringFlag{
&cli.StringFlag{
Name: "title",
Usage: "set the doodad title",
},
cli.StringFlag{
&cli.StringFlag{
Name: "author",
Usage: "set the doodad author",
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "tag, t",
Usage: "set a key/value tag on the doodad, in key=value format. Empty value deletes the tag.",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "hide",
Usage: "Hide the doodad from the palette",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "unhide",
Usage: "Unhide the doodad from the palette",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "lock",
Usage: "write-lock the level file",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "unlock",
Usage: "remove the write-lock on the level file",
},
@ -60,7 +60,7 @@ func init() {
)
}
var filenames = c.Args()
var filenames = c.Args().Slice()
for _, filename := range filenames {
if err := editDoodad(c, filename); err != nil {
log.Error("%s: %s", filename, err)

View File

@ -10,47 +10,48 @@ import (
)
// EditLevel allows writing level metadata.
var EditLevel cli.Command
var EditLevel *cli.Command
func init() {
EditLevel = cli.Command{
EditLevel = &cli.Command{
Name: "edit-level",
Usage: "update metadata for a Level file",
ArgsUsage: "<filename.level>",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "limit output (don't show doodad data at the end)",
},
cli.StringFlag{
&cli.StringFlag{
Name: "title",
Usage: "set the level title",
},
cli.StringFlag{
&cli.StringFlag{
Name: "author",
Usage: "set the level author",
},
cli.StringFlag{
&cli.StringFlag{
Name: "password",
Usage: "set the level password",
},
cli.StringFlag{
&cli.StringFlag{
Name: "type",
Usage: "set the page type. One of: Unbounded, Bounded, NoNegativeSpace, Bordered",
},
cli.StringFlag{
&cli.StringFlag{
Name: "max-size",
Usage: "set the page max size (WxH format, like 2550x3300)",
},
cli.StringFlag{
&cli.StringFlag{
Name: "wallpaper",
Usage: "set the wallpaper filename",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "lock",
Usage: "write-lock the level file",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "unlock",
Usage: "remove the write-lock on the level file",
},
@ -63,7 +64,7 @@ func init() {
)
}
var filenames = c.Args()
var filenames = c.Args().Slice()
for _, filename := range filenames {
if err := editLevel(c, filename); err != nil {
log.Error("%s: %s", filename, err)

View File

@ -10,15 +10,15 @@ import (
)
// InstallScript to add the script to a doodad file.
var InstallScript cli.Command
var InstallScript *cli.Command
func init() {
InstallScript = cli.Command{
InstallScript = &cli.Command{
Name: "install-script",
Usage: "install the JavaScript source to a doodad",
ArgsUsage: "<index.js> <filename.doodad>",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "key",
Usage: "chroma key color for transparency on input image files",
Value: "#ffffff",
@ -34,8 +34,8 @@ func init() {
var (
args = c.Args()
scriptFile = args[0]
doodadFile = args[1]
scriptFile = args.Get(0)
doodadFile = args.Get(1)
)
// Read the JavaScript source.

View File

@ -13,28 +13,29 @@ import (
)
// Show information about a Level or Doodad file.
var Show cli.Command
var Show *cli.Command
func init() {
Show = cli.Command{
Show = &cli.Command{
Name: "show",
Usage: "show information about a level or doodad file",
ArgsUsage: "<.level or .doodad>",
Flags: []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "actors",
Usage: "print verbose actor data in Level files",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "chunks",
Usage: "print verbose data about all the pixel chunks in a file",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "script",
Usage: "print the script from a doodad file and exit",
},
cli.BoolFlag{
Name: "verbose, v",
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "print verbose output (all verbose flags enabled)",
},
},
@ -46,7 +47,7 @@ func init() {
)
}
filenames := c.Args()
filenames := c.Args().Slice()
for _, filename := range filenames {
switch strings.ToLower(filepath.Ext(filename)) {
case enum.LevelExt:

View File

@ -44,13 +44,13 @@ func main() {
)
app.Flags = []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug level logging",
},
}
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
commands.Convert,
commands.Show,
commands.EditLevel,

View File

@ -55,15 +55,17 @@ func main() {
)
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "enable debug level logging",
},
cli.BoolFlag{
Name: "edit, e",
&cli.BoolFlag{
Name: "edit",
Aliases: []string{"e"},
Usage: "edit the map given on the command line (instead of play it)",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "guitest",
Usage: "enter the GUI Test scene on startup",
},