From 378ca66cd0cf39e3f8d90bf87e5e70f4643dcf39 Mon Sep 17 00:00:00 2001 From: jienfak Date: Tue, 7 Jan 2020 06:22:16 +0500 Subject: [PATCH] echo: "\n" option implemented. --- echo/echo.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/echo/echo.go b/echo/echo.go index 9ee0c81..d9e2229 100644 --- a/echo/echo.go +++ b/echo/echo.go @@ -7,15 +7,18 @@ import ( ) func Run(args []string) int { + var nflag bool flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) + flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.") flagSet.Parse(args[1:]) - args = args[1:] - status := 0 + args = flagSet.Args() l := len(args) - 1 for i, s := range args { fmt.Print(s) if i!=l { fmt.Print(" ") } } - fmt.Print("\n") - return status + if !nflag { + fmt.Print("\n") + } + return 0 }