echo: added delimiter option.

This commit is contained in:
k1574 2021-10-06 04:15:20 +05:00
parent a084344702
commit 2ce694b77a

View file

@ -6,19 +6,26 @@ import (
"flag" "flag"
) )
var(
del string
eol = "\n"
)
func Run(args []string) int { func Run(args []string) int {
var nflag bool var nflag bool
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.") flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.")
flagSet.StringVar(&del, "d", " ", "Delimiter of arguments")
flagSet.Parse(args[1:]) flagSet.Parse(args[1:])
args = flagSet.Args() args = flagSet.Args()
l := len(args) - 1 l := len(args) - 1
for i, s := range args { for i, s := range args {
fmt.Print(s) fmt.Print(s)
if i!=l { fmt.Print(" ") } if i!=l { fmt.Print(del) }
} }
if !nflag { if !nflag {
fmt.Print("\n") fmt.Print(eol)
} }
return 0 return 0
} }