yes: "-N" option implemented.
This commit is contained in:
parent
97a5d794e1
commit
58bb9ea140
1 changed files with 12 additions and 2 deletions
14
yes/yes.go
14
yes/yes.go
|
@ -8,10 +8,19 @@ import(
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/jienfak/goblin/input"
|
"github.com/jienfak/goblin/input"
|
||||||
)
|
)
|
||||||
|
var(
|
||||||
|
nArg int
|
||||||
|
)
|
||||||
|
|
||||||
func yes(s string){
|
func yes(s string){
|
||||||
for{
|
if nArg<0{
|
||||||
fmt.Print(s)
|
for{
|
||||||
|
fmt.Print(s)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i:=0 ; i<nArg ; i+=1 {
|
||||||
|
fmt.Print(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +36,7 @@ func Run(args []string) int {
|
||||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||||
flagSet.BoolVar(&stdinFlag, "s", false, "Read string from stdin.")
|
flagSet.BoolVar(&stdinFlag, "s", false, "Read string from stdin.")
|
||||||
flagSet.BoolVar(&nFlag, "n", false, "Do not add net line character.")
|
flagSet.BoolVar(&nFlag, "n", false, "Do not add net line character.")
|
||||||
|
flagSet.IntVar(&nArg, "N", -1, "Repeat input N times. Negative value means infinite cycle.")
|
||||||
flagSet.Usage = func() {
|
flagSet.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] [string]\n", arg0, arg0)
|
fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] [string]\n", arg0, arg0)
|
||||||
flagSet.PrintDefaults()
|
flagSet.PrintDefaults()
|
||||||
|
|
Loading…
Reference in a new issue