feat: added additional flags and updated the CLI library usage.

This commit is contained in:
Andrey Parhomenko 2024-09-21 03:38:28 +05:00
parent cde559b111
commit bf6241ea61
2 changed files with 49 additions and 15 deletions

View file

@ -17,7 +17,7 @@ var (
Tool = mtool.T("pin").Func(Run).Desc(
"print all the possible PIN combinations made of custom characters",
).Usage(
"<tmpl_chars>",
"",
)
)
@ -68,13 +68,25 @@ func Run(flags *mtool.Flags) {
length int
rFlag bool
)
var (
chrsString string
chrs []rune
)
flags.StringVar(
&chrsString,
"c",
"0123456789",
"character set for substitution",
"COMBO_CHARS",
)
flags.IntVar(
&lval, "min", 0,
&lval, "min", 1,
"min length of the output pins",
)
flags.BoolVar(
&Lflag, "m", false,
"set the '-min' flag value to 1 (overrides it)",
"set the '-min' flag value to 1 (overrides the '-min' it)",
)
flags.IntVar(
&length, "max", 0,
@ -84,17 +96,17 @@ func Run(flags *mtool.Flags) {
flags.IntVar(&nVal, "rep", 1, "max repeats of the rune." )
flags.BoolVar(&rFlag, "R", false, "make the maximum repeat equal to the length of input chars" )
args := flags.Parse()
_ = flags.Parse()
if len(args) == 0 {
/*if len(args) == 0 {
flags.Usage()
os.Exit(1)
}
}*/
chrs = []rune(args[0])
chrs = []rune(chrsString)
if length == 0 {
length = len(chrs)
length = 4
}
if Lflag {

View file

@ -13,22 +13,44 @@ var(
Tool = mtool.T("tmpl").Func(Run).Desc(
"substitute the inputted runes with the specified words",
).Usage(
"[n_utf8_chars] [n_strings]",
"[n_strings]",
)
)
func Run(flags *mtool.Flags) {
var (
chrsString string
chrs []rune
skip bool
)
flags.StringVar(
&chrsString,
"c",
"0123456789",
"character set for substitution",
"COMBO_CHARS",
)
flags.BoolVar(
&skip,
"skip",
false,
"skip and do not substitute not fitting chars",
)
delim = '\n'
args := flags.Parse()
if len(args)<2 || len(args[0]) != len(args)-1 {
/*if len(args)<2 || len(args[0]) != len(args)-1 {
flags.Usage()
os.Exit(1)
}
}*/
chrs := []rune(args[0])
args = args[1:]
chrs = []rune(chrsString)
//args = args[1:]
tmpl := make(map[rune] string)
for i, s := range args {
@ -44,7 +66,7 @@ func Run(flags *mtool.Flags) {
s = s[:len(s)-1]
for _, c := range s {
s, ok := tmpl[c]
if !ok {
if !skip && !ok {
s = string(c)
}
fmt.Printf("%s", s)