diff options
Diffstat (limited to 'argv.parseOsArgs.go')
| -rw-r--r-- | argv.parseOsArgs.go | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index 70231ef..ac5be15 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -10,6 +10,42 @@ import ( "go.wit.com/log" ) +// todo: this is wrong +func (pb *Argv) GetCmd() string { + var curcmd string + for _, s := range os.Args[1:] { + if strings.HasPrefix(s, "-") { + // option is something like --verbose + // skip these. they are not subcommands + continue + } + // found the subcommand + curcmd = s + break + } + if pb.Partial == "'"+curcmd+"'" { + // not really a command, it's just a partially inputed string from the user + return "" + } + return curcmd +} + +// todo: this is dumb +func (pb *Argv) getSubSubCmd() string { + var subcmd string + 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) + } + subcmd = s + } + return subcmd +} + func (pb *Argv) parseOsArgs() { // this shouldn't really happen. OS/POSIX error? if len(os.Args) == 0 { @@ -19,45 +55,45 @@ func (pb *Argv) parseOsArgs() { // there is nothing on the command line. user just ran "forge" and hit enter if len(os.Args) == 1 { - pb.Arg0 = os.Args[0] + // pb.Arg0 = os.Args[0] return } // try to setup bash autocomplete and exit if len(os.Args) > 1 && os.Args[1] == "--bash" { - pb.SetupAuto = true + me.setupAuto = true return } // try to setup zsh autocomplete and exit if len(os.Args) > 1 && os.Args[1] == "--zsh" { - pb.SetupAuto = true + me.setupAuto = true return } // set debug flag if --argvdebug is passed for _, s := range os.Args { if s == "--argvdebug" { - pb.Debug = true + me.debug = true } // deprecate if s == "--autodebug" { - pb.Debug = true + me.debug = true } } // wtf is this. I've forgotten. todo: figure this out - if len(os.Args) > 1 && os.Args[1] == pb.Argname { - pb.IsAuto = true + if len(os.Args) > 1 && os.Args[1] == pb.AppInfo.APPNAME { + me.isAuto = true parts := strings.Split(os.Getenv("COMP_LINE"), " ") - pb.Debug = true + me.debug = true log.Fprintf(os.Stderr, "\n") pb.Debugf("MATCH Partial os.Args=%v COMP_LINE=%v", os.Args, os.Getenv("COMP_LINE")) // log.Fprintf(os.Stdout, "jcarr") if len(parts) > 0 { - pb.Arg0 = parts[0] + // pb.Arg0 = parts[0] } - pb.Arg1 = os.Args[1] + // pb.Arg1 = os.Args[1] os.Exit(0) } @@ -73,16 +109,8 @@ func (pb *Argv) parseOsArgs() { for _, s := range os.Args[1:] { pb.Real = append(pb.Real, s) } - for _, s := range os.Args[1:] { - if strings.HasPrefix(s, "-") { - // option is something like --verbose - // skip these. they are not subcommands - continue - } - // found the subcommand - pb.Cmd = s - break - } + // found the subcommand + // pb.Cmd = pb.findCmd() // exit here. not autocomplete // todo: actually finish parsing the pb. is it safe to continue from here? return @@ -91,17 +119,16 @@ func (pb *Argv) parseOsArgs() { // the shell is trying to get autocomplete information // initial PB setup - pb.IsAuto = true - pb.Arg0 = os.Args[0] - pb.Arg1 = os.Args[1] + me.isAuto = true + // pb.Arg0 = os.Args[0] + // pb.Arg1 = os.Args[1] pb.Partial = os.Args[2] - pb.Arg3 = os.Args[3] + // 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 } @@ -123,36 +150,10 @@ func (pb *Argv) parseOsArgs() { } 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 - } - 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 + + // this is dumb 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) } - // if pb.Cmd == "" { - // pb.Cmd = strings.Join(pb.Argv, "BLAH") - // } return } |
