bb/echo/echo.go

25 lines
438 B
Go
Raw Normal View History

2019-10-30 02:54:45 +03:00
/* Simple 'echo' implementation. */
package echo
import (
2020-01-06 10:28:48 +03:00
"fmt"
2019-10-30 02:54:45 +03:00
"flag"
)
func Run(args []string) int {
2020-01-07 04:22:16 +03:00
var nflag bool
2019-10-30 02:54:45 +03:00
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
2020-01-07 04:22:16 +03:00
flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.")
2019-10-30 02:54:45 +03:00
flagSet.Parse(args[1:])
2020-01-07 04:22:16 +03:00
args = flagSet.Args()
2020-01-06 10:28:48 +03:00
l := len(args) - 1
for i, s := range args {
fmt.Print(s)
if i!=l { fmt.Print(" ") }
2019-10-30 02:54:45 +03:00
}
2020-01-07 04:22:16 +03:00
if !nflag {
fmt.Print("\n")
}
return 0
2019-10-30 02:54:45 +03:00
}