diff --git a/pin/pin.go b/pin/pin.go index 5cbcda8..0479faa 100644 --- a/pin/pin.go +++ b/pin/pin.go @@ -4,16 +4,14 @@ import ( "fmt" //"strconv" //"log" - "surdeus.su/core/cli/mtool" + "io" "os" + + "surdeus.su/core/cli/mtool" ) var ( - Lflag bool - lval int delim rune = '\n' - nVal int - chrs []rune Tool = mtool.T("pin").Func(Run).Desc( "print all the possible PIN combinations made of custom characters", ).Usage( @@ -22,39 +20,46 @@ var ( ) func Pow(x, p int) int { - ret := 1 + ret := 1 for i:=0 ; i

nVal { + if a[i] > maxReps { return false } } @@ -63,38 +68,55 @@ func Fits(s []rune) bool { return true } -func Run(flags *mtool.Flags) { +func Run( + flags *mtool.Flags, +) { + CustomRun( + os.Stdin, + os.Stdout, + flags, + ) +} + +func CustomRun( + input io.Reader, + output io.Writer, + flags *mtool.Flags, +) { var ( length int rFlag bool + mFlag bool + minLength int + maxReps int ) var ( - chrsString string + charsString string chrs []rune ) flags.StringVar( - &chrsString, + &charsString, "c", "0123456789", "character set for substitution", "COMBO_CHARS", ) flags.IntVar( - &lval, "min", 1, + &minLength, "min-len", 1, "min length of the output pins", ) flags.BoolVar( - &Lflag, "m", false, - "set the '-min' flag value to 1 (overrides the '-min' it)", + &mFlag, "m", false, + "set the '-min-len' flag value to 1 (overrides the '-min' it)", ) flags.IntVar( &length, "max", 0, "max length of the output pins", ) - 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.IntVar(&maxReps, "max-reps", 1, "max repeats of the rune." ) + flags.BoolVar(&rFlag, "r", false, "make the -max-reps value equal to the length of input chars" ) _ = flags.Parse() @@ -103,30 +125,30 @@ func Run(flags *mtool.Flags) { os.Exit(1) }*/ - chrs = []rune(chrsString) + chrs = []rune(charsString) if length == 0 { length = 4 } - if Lflag { - lval = 1 + if mFlag { + minLength = 1 } if rFlag { - nVal = len(chrs) + maxReps = len(chrs) } - if lval != 0 { - if lval > length { + if minLength != 0 { + if minLength > length { flags.Usage() os.Exit(1) } - for i := lval ; i<=length ; i++ { - printPins(chrs, i) + for i := minLength ; i<=length ; i++ { + FprintPins(output, chrs, i) } } else { - printPins(chrs, length) + FprintPins(output, chrs, length) } }