diff --git a/arguments.go b/arguments.go index 104171c..629aa96 100644 --- a/arguments.go +++ b/arguments.go @@ -61,10 +61,10 @@ type commandArg struct { // validate arguments string from CommandsFile // and return the validatedArgs as map -func (c *CommandsFile) validateArgs(args []string) (map[string]*commandArg, error) { +func (c *CommandsFile) validateArgs(args []string) ([]*commandArg, error) { // init map - validatedArgs := make(map[string]*commandArg, 0) + var validatedArgs []*commandArg // empty string - empty args if len(args) == 0 { @@ -102,7 +102,7 @@ func (c *CommandsFile) validateArgs(args []string) (map[string]*commandArg, erro g.Unlock() // check for duplicate argument names - if a, ok := validatedArgs[argumentName]; ok { + if a, ok := containsArg(validatedArgs, argumentName); ok { Log.Error("argument label ", a.name, " was used twice") return nil, ErrDuplicateArgumentNames } @@ -138,12 +138,12 @@ func (c *CommandsFile) validateArgs(args []string) (map[string]*commandArg, erro } // add to validatedArgs - validatedArgs[argumentName] = &commandArg{ + validatedArgs = append(validatedArgs, &commandArg{ name: argumentName, argType: k, optional: opt, defaultValue: defaultValue, - } + }) } else { return nil, errors.New("invalid argument declaration: " + s) } @@ -184,7 +184,8 @@ func (c *command) parseArguments(args []string) (string, map[string]string, erro return "", argValues, errors.New("invalid argument: " + val) } - if cmdArg, ok = c.args[argSlice[0]]; !ok { + cmdArg, ok = containsArg(c.args, argSlice[0]) + if !ok { return "", argValues, errors.New(ErrInvalidArgumentLabel.Error() + ": " + ansi.Red + argSlice[0] + cp.Reset) } @@ -202,8 +203,8 @@ func (c *command) parseArguments(args []string) (string, map[string]string, erro return "", argValues, errors.New(ErrInvalidArgumentType.Error() + ": " + err.Error() + ", label=" + cmdArg.name + ", value=" + argSlice[1]) } - // set value in c.args - c.args[argSlice[0]].value = argSlice[1] + // temporarily set value on arg + cmdArg.value = argSlice[1] } else { return "", argValues, errors.New("invalid argument: " + val) } @@ -382,3 +383,12 @@ func resolveEnvironment(input string) string { return input } + +func containsArg(args []*commandArg, name string) (*commandArg, bool) { + for _, a := range args { + if a.name == name { + return a, true + } + } + return nil, false +} \ No newline at end of file diff --git a/builtins.go b/builtins.go index da31920..8f09d5d 100644 --- a/builtins.go +++ b/builtins.go @@ -20,6 +20,7 @@ package main import ( "io/ioutil" + "log" "os" "os/exec" "sort" @@ -251,7 +252,7 @@ func printLine(line string, lastElem, lastItem bool) { } // format commandArg map into human readable string -func getArgumentString(args map[string]*commandArg) string { +func getArgumentString(args []*commandArg) string { if len(args) == 0 { return "" @@ -265,13 +266,18 @@ func getArgumentString(args map[string]*commandArg) string { ) // sort args alphabetically before printing, so the order does not change in between multiple runs. - for name := range args { - names = append(names, name) + for _, a := range args { + names = append(names, a.name) } sort.Strings(names) for _, name := range names { - arg := args[name] + + arg, ok := containsArg(args, name) + if !ok { + log.Fatal("could not find arg: " + name) + } + var t = cp.CmdArgType + strings.Title(arg.argType.String()) if arg.optional { if arg.defaultValue != "" { diff --git a/command.go b/command.go index 4d99123..1cf4df2 100644 --- a/command.go +++ b/command.go @@ -72,7 +72,7 @@ type command struct { // arguments for the command // mapped labels to commandArg instances - args map[string]*commandArg + args []*commandArg // short descriptive text description string @@ -762,7 +762,7 @@ func initScript(path string) error { cmd := &command{ path: path, name: name, - args: make(map[string]*commandArg, 0), + args: []*commandArg{}, description: "", help: "", buildNumber: false, diff --git a/events.go b/events.go index 05e8afd..4cba20e 100644 --- a/events.go +++ b/events.go @@ -40,7 +40,7 @@ var ( ErrInvalidUsage = errors.New("invalid usage") ) -// temporarely disable change event +// temporarily disable change event func blockWriteEvent() { disableWriteEventMutex.Lock() disableWriteEvent = true diff --git a/tests/zeus/config.yml b/tests/zeus/config.yml index ed986d5..a935bfd 100755 --- a/tests/zeus/config.yml +++ b/tests/zeus/config.yml @@ -4,7 +4,7 @@ # /_____ \\___ >____//____ > # \/ \/ \/ # Build System -# v0.9.1 +# v0.9.7 # autoFormat: false diff --git a/tests/zeus/data.yml b/tests/zeus/data.yml index d569ebc..14fccf3 100755 --- a/tests/zeus/data.yml +++ b/tests/zeus/data.yml @@ -4,7 +4,7 @@ # /_____ \\___ >____//____ > # \/ \/ \/ # Build System -# v0.9.1 +# v0.9.7 # buildNumber: 3 @@ -12,9 +12,9 @@ deadline: "" milestones: [] aliases: {} events: - 0e01507e29e37318: + 1184e2da72dbcd1b: name: config watcher - id: 0e01507e29e37318 + id: 1184e2da72dbcd1b path: tests/zeus/config.yml op: 2 fileextension: .yml diff --git a/tests/zeus/generated/build.sh b/tests/zeus/generated/build.sh index d78658a..db8d599 100755 --- a/tests/zeus/generated/build.sh +++ b/tests/zeus/generated/build.sh @@ -1,10 +1,10 @@ #!/bin/bash -# generated by ZEUS v0.9.1 -# Timestamp: [Thu Feb 11 15:52:04 2021] +# generated by ZEUS v0.9.7 +# Timestamp: [Thu Feb 18 17:21:55 2021] binaryName="zeus" buildDir="bin" -version="0.9.1" +version="0.9.7" diff --git a/version.go b/version.go index cf5432b..4fa9642 100644 --- a/version.go +++ b/version.go @@ -20,4 +20,4 @@ package main // zeus version // generated with the gen-version command -var version = "0.9.7" +var version = "0.9.8" diff --git a/zeus/commands.yml b/zeus/commands.yml index 43ba322..75f197c 100644 --- a/zeus/commands.yml +++ b/zeus/commands.yml @@ -17,7 +17,7 @@ language: bash globals: binaryName: zeus buildDir: bin - version: 0.9.7 + version: 0.9.8 # all commands # available fields: