feat: added custom args to be able to call the tools in more flexablie way.
This commit is contained in:
parent
cc0131c812
commit
561b23ffc8
2 changed files with 20 additions and 21 deletions
|
@ -9,21 +9,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Flags struct {
|
type Flags struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
tool *Tool
|
tool *Tool
|
||||||
args []string
|
args []string
|
||||||
parsedArgs []string
|
parsedArgs []string
|
||||||
envNameMap map[string] []string
|
customArgs []any
|
||||||
|
envNameMap map[string][]string
|
||||||
envMap map[string]string
|
envMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ToolMap map[string] *Tool
|
type ToolMap map[string]*Tool
|
||||||
|
|
||||||
func (flags *Flags) wasPassed(name string) bool {
|
func (flags *Flags) wasPassed(name string) bool {
|
||||||
found := false
|
found := false
|
||||||
flags.Visit(func(f *flag.Flag){
|
flags.Visit(func(f *flag.Flag) {
|
||||||
if f.Name == name {
|
if f.Name == name {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
@ -150,4 +150,3 @@ func (flags *Flags) Args() []string {
|
||||||
func (flags *Flags) Tool() *Tool {
|
func (flags *Flags) Tool() *Tool {
|
||||||
return flags.tool
|
return flags.tool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package mtool
|
package mtool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"text/tabwriter"
|
|
||||||
"strings"
|
|
||||||
"flag"
|
"flag"
|
||||||
"sort"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tool struct {
|
type Tool struct {
|
||||||
|
@ -107,7 +107,7 @@ func (t *Tool) PrintSubs(out io.Writer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tool) Run(args []string) {
|
func (t *Tool) Run(args []string, customArgs ...any) {
|
||||||
var(
|
var(
|
||||||
usageTool *Tool
|
usageTool *Tool
|
||||||
)
|
)
|
||||||
|
@ -120,6 +120,7 @@ func (t *Tool) Run(args []string) {
|
||||||
FlagSet : flagSet,
|
FlagSet : flagSet,
|
||||||
envMap: make(map[string]string),
|
envMap: make(map[string]string),
|
||||||
envNameMap: make(map[string] []string),
|
envNameMap: make(map[string] []string),
|
||||||
|
customArgs: customArgs,
|
||||||
}
|
}
|
||||||
out := flags.Output()
|
out := flags.Output()
|
||||||
flags.Usage = func() {
|
flags.Usage = func() {
|
||||||
|
@ -253,7 +254,7 @@ func (t *Tool) Run(args []string) {
|
||||||
|
|
||||||
sub := t.subs[toolName]
|
sub := t.subs[toolName]
|
||||||
usageTool = sub
|
usageTool = sub
|
||||||
sub.Run(args)
|
sub.Run(args, customArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the built-in
|
// Returns the built-in
|
||||||
|
@ -278,4 +279,3 @@ func FormatInCode(
|
||||||
}
|
}
|
||||||
return desc
|
return desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue