12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /* Yes program implementation. */
- package yes
- import (
- "os"
- "fmt"
- "strings"
- "surdeus.su/util/bb/input"
- "surdeus.su/core/cli/mtool"
- )
- var (
- nArg int
- )
- func yes(s string) {
- if nArg < 0 {
- for {
- fmt.Print(s)
- }
- } else {
- for i := 0; i < nArg; i += 1 {
- fmt.Print(s)
- }
- }
- }
- func Run(flagSet *mtool.Flags) {
- var (
- stdinFlag bool
- nFlag bool
- s string
- )
- flagSet.BoolVar(&stdinFlag, "s", false, "Read string from stdin.")
- 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.Parse()
- args := flagSet.Args()
- if stdinFlag {
- in, _ := input.ReadAllRaw(os.Stdin)
- s = string(in)
- } else {
- if len(args) > 0 {
- s = strings.Join(args, " ")
- } else {
- s = "y"
- }
- }
- if !nFlag {
- s += "\n"
- }
- yes(s)
- }
|