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