diff options
Diffstat (limited to 'argv.parseOsArgs.go')
| -rw-r--r-- | argv.parseOsArgs.go | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index eb6f7d6..8623138 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -85,66 +85,71 @@ func (pb *Argv) parseArgv() { return } - // should we do auto complete here? - if len(os.Args) > 1 && os.Args[1] == "--auto-complete" { - pb.IsAuto = true - pb.Arg0 = os.Args[0] - pb.Arg1 = os.Args[1] - pb.Partial = os.Args[2] - pb.Arg3 = os.Args[3] - if len(os.Args) < 5 { - // the user is doing autocomplete on the command itself - pb.Partial = "" - pb.Cmd = "" - pb.Real = []string{""} - return + // the shell is trying to get autocomplete information + + // initial PB setup + pb.IsAuto = true + pb.Arg0 = os.Args[0] + pb.Arg1 = os.Args[1] + pb.Partial = os.Args[2] + pb.Arg3 = os.Args[3] + + if len(os.Args) < 5 { + // the user is doing autocomplete on the command itself + // no subcommand. user has done "forge <TAB><TAB>" + pb.Partial = "" + pb.Cmd = "" + pb.Real = []string{""} + return + } + + // figure out if there is a subcommand or a partial match + if pb.Partial == "''" { + pb.Partial = "" + } + + // pb.Argv = os.Args[4:] + for _, s := range os.Args[4:] { + if s == "--autodebug" { + continue } - if pb.Partial == "''" { - pb.Partial = "" + tmp := strings.Trim(pb.Partial, "'") + if tmp == s { + // don't put pb.Partial into Argv + continue } - // pb.Argv = os.Args[4:] - for _, s := range os.Args[4:] { - if s == "--autodebug" { - continue - } - tmp := strings.Trim(pb.Partial, "'") - if tmp == s { - // don't put pb.Partial into Argv - continue - } - pb.Real = append(pb.Real, s) - } - // set pb.Cmd to the first thing that doesn't have a '-' arg - for _, s := range pb.Real { - if strings.HasPrefix(s, "-") { - continue - } - pb.Cmd = s - break + pb.Real = append(pb.Real, s) + } + // set pb.Cmd to the first thing that doesn't have a '-' arg + for _, s := range pb.Real { + if strings.HasPrefix(s, "-") { + continue } - if pb.Partial == "'"+pb.Cmd+"'" { - // not really a command, it's just a partially inputed string from the user - pb.Cmd = "" + pb.Cmd = s + break + } + if pb.Partial == "'"+pb.Cmd+"'" { + // not really a command, it's just a partially inputed string from the user + pb.Cmd = "" + } + // try to figure out what the last argv is + for _, s := range pb.Real { + p := fmt.Sprintf("'%s'", s) + if pb.Partial == p { + pb.Debugf("DEBUG: Last argv MATCHES Partial %s %s", s, p) + continue + } else { + pb.Debugf("DEBUG: Last argv DOES NOT MATCH Partial %s %s", s, p) } - // try to figure out what the last argv is - for _, s := range pb.Real { - p := fmt.Sprintf("'%s'", s) - if pb.Partial == p { - pb.Debugf("DEBUG: Last argv MATCHES Partial %s %s", s, p) - continue - } else { - pb.Debugf("DEBUG: Last argv DOES NOT MATCH Partial %s %s", s, p) - } - pb.Last = s - if strings.HasPrefix(s, "-") { - // skip args like -test --verbose when sending subcommands to go-args for help text - continue - } - pb.Goargs = append(pb.Goargs, s) + pb.Last = s + if strings.HasPrefix(s, "-") { + // skip args like -test --verbose when sending subcommands to go-args for help text + continue } - // if pb.Cmd == "" { - // pb.Cmd = strings.Join(pb.Argv, "BLAH") - // } + pb.Goargs = append(pb.Goargs, s) } + // if pb.Cmd == "" { + // pb.Cmd = strings.Join(pb.Argv, "BLAH") + // } return } |
