bb/tool/echo/echo.go

33 lines
493 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"
2023-11-11 12:51:15 +03:00
"github.com/omnipunk/cli/mtool"
2019-10-30 02:54:45 +03:00
)
2021-10-06 02:15:20 +03:00
var(
del string
eol = "\n"
)
2023-03-24 16:54:51 +03:00
func Run(flagSet *mtool.Flags) {
2020-01-07 04:22:16 +03:00
var nflag bool
2023-03-24 16:54:51 +03:00
2020-01-07 04:22:16 +03:00
flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.")
2021-10-06 02:15:20 +03:00
flagSet.StringVar(&del, "d", " ", "Delimiter of arguments")
2023-03-24 16:54:51 +03:00
flagSet.Parse()
args := flagSet.Args()
2020-01-06 10:28:48 +03:00
l := len(args) - 1
for i, s := range args {
fmt.Print(s)
2021-10-06 02:15:20 +03:00
if i!=l { fmt.Print(del) }
2019-10-30 02:54:45 +03:00
}
2020-01-07 04:22:16 +03:00
if !nflag {
2021-10-06 02:15:20 +03:00
fmt.Print(eol)
2020-01-07 04:22:16 +03:00
}
2021-10-06 02:15:20 +03:00
2019-10-30 02:54:45 +03:00
}