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,12 +9,12 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
|
||||
type Flags struct {
|
||||
*flag.FlagSet
|
||||
tool *Tool
|
||||
args []string
|
||||
parsedArgs []string
|
||||
customArgs []any
|
||||
envNameMap map[string][]string
|
||||
envMap map[string]string
|
||||
}
|
||||
|
@ -150,4 +150,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