1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package argvpb
// sends the autocomplete strings to the shell
// also where custom strings are pulled in from the application
// calls into go-args for strings parsed by MustParse()
import (
"fmt"
"os"
"strings"
"go.wit.com/log"
)
// the application must send a string "help run list"
func (pb *Argv) SendString(sendthis string) {
pb.SendStrings(strings.Split(sendthis, " "))
}
// the application must send an array []string{"help", "run", "list"}
func (pb *Argv) SendStrings(parts []string) {
// parts := strings.Split(sendthis, " ")
var all []string
for _, part := range parts {
var found bool
for _, s := range os.Args {
if s == part {
found = true
}
}
if found {
continue
}
all = append(all, part)
}
fmt.Printf("%s", strings.Join(all, " "))
}
// try out a new name. also, this whole thing is dumb and needs to be redone
func (pb *Argv) GenerateSubCommandStrings(cmd ...string) {
pb.SubCommand(cmd...)
}
func (pb *Argv) SubCommand(cmd ...string) {
if pb.Debug {
if me.examples == nil {
pb.Debugf("WRITE DEBUG: argv.Examples() not defined")
// log.Fprintf(os.Stderr, "\n")
// log.Fprintf(os.Stderr, "examples was nil\n")
// log.Fprintf(os.Stderr, "\n")
} else {
log.Fprintf(os.Stderr, "\n")
log.Fprintf(os.Stderr, "\n")
log.Fprintf(os.Stderr, "Examples:\n")
for _, line := range strings.Split(me.examples(), "\n") {
log.Fprintf(os.Stderr, " %s\n", line)
}
// log.Fprintf(os.Stderr, "\n")
}
// last working line: me.writeHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
partial := strings.Trim(pb.Partial, "'")
me.writeHelpForAutocompleteDebugFunc(partial, cmd...)
// me.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
// me.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
} else {
// last working: f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
// last working: me.writeHelpForAutocomplete(f, os.Stdout, partial, cmd...)
partial := strings.Trim(pb.Partial, "'")
me.writeHelpForAutocompleteFunc(partial, cmd...)
}
os.Exit(0)
}
|