feat: added additional flags and updated the CLI library usage.
This commit is contained in:
parent
cde559b111
commit
bf6241ea61
2 changed files with 49 additions and 15 deletions
28
pin/pin.go
28
pin/pin.go
|
@ -17,7 +17,7 @@ var (
|
||||||
Tool = mtool.T("pin").Func(Run).Desc(
|
Tool = mtool.T("pin").Func(Run).Desc(
|
||||||
"print all the possible PIN combinations made of custom characters",
|
"print all the possible PIN combinations made of custom characters",
|
||||||
).Usage(
|
).Usage(
|
||||||
"<tmpl_chars>",
|
"",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,13 +68,25 @@ func Run(flags *mtool.Flags) {
|
||||||
length int
|
length int
|
||||||
rFlag bool
|
rFlag bool
|
||||||
)
|
)
|
||||||
|
var (
|
||||||
|
chrsString string
|
||||||
|
chrs []rune
|
||||||
|
)
|
||||||
|
|
||||||
|
flags.StringVar(
|
||||||
|
&chrsString,
|
||||||
|
"c",
|
||||||
|
"0123456789",
|
||||||
|
"character set for substitution",
|
||||||
|
"COMBO_CHARS",
|
||||||
|
)
|
||||||
flags.IntVar(
|
flags.IntVar(
|
||||||
&lval, "min", 0,
|
&lval, "min", 1,
|
||||||
"min length of the output pins",
|
"min length of the output pins",
|
||||||
)
|
)
|
||||||
flags.BoolVar(
|
flags.BoolVar(
|
||||||
&Lflag, "m", false,
|
&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(
|
flags.IntVar(
|
||||||
&length, "max", 0,
|
&length, "max", 0,
|
||||||
|
@ -84,17 +96,17 @@ func Run(flags *mtool.Flags) {
|
||||||
flags.IntVar(&nVal, "rep", 1, "max repeats of the rune." )
|
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" )
|
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()
|
flags.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
chrs = []rune(args[0])
|
chrs = []rune(chrsString)
|
||||||
|
|
||||||
if length == 0 {
|
if length == 0 {
|
||||||
length = len(chrs)
|
length = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
if Lflag {
|
if Lflag {
|
||||||
|
|
36
tmpl/tmpl.go
36
tmpl/tmpl.go
|
@ -8,27 +8,49 @@ import (
|
||||||
"surdeus.su/core/cli/mtool"
|
"surdeus.su/core/cli/mtool"
|
||||||
)
|
)
|
||||||
|
|
||||||
var(
|
var (
|
||||||
delim rune
|
delim rune
|
||||||
Tool = mtool.T("tmpl").Func(Run).Desc(
|
Tool = mtool.T("tmpl").Func(Run).Desc(
|
||||||
"substitute the inputted runes with the specified words",
|
"substitute the inputted runes with the specified words",
|
||||||
).Usage(
|
).Usage(
|
||||||
"[n_utf8_chars] [n_strings]",
|
"[n_strings]",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func Run(flags *mtool.Flags) {
|
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'
|
delim = '\n'
|
||||||
args := flags.Parse()
|
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()
|
flags.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
chrs := []rune(args[0])
|
chrs = []rune(chrsString)
|
||||||
args = args[1:]
|
//args = args[1:]
|
||||||
|
|
||||||
tmpl := make(map[rune] string)
|
tmpl := make(map[rune] string)
|
||||||
for i, s := range args {
|
for i, s := range args {
|
||||||
|
@ -44,7 +66,7 @@ func Run(flags *mtool.Flags) {
|
||||||
s = s[:len(s)-1]
|
s = s[:len(s)-1]
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
s, ok := tmpl[c]
|
s, ok := tmpl[c]
|
||||||
if !ok {
|
if !skip && !ok {
|
||||||
s = string(c)
|
s = string(c)
|
||||||
}
|
}
|
||||||
fmt.Printf("%s", s)
|
fmt.Printf("%s", s)
|
||||||
|
|
Loading…
Reference in a new issue