newnix: echo: Remake flags using.
This commit is contained in:
parent
277a997113
commit
4c2634b733
1 changed files with 16 additions and 10 deletions
|
@ -2,21 +2,27 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
strsId := 1
|
newLineFlagPtr := flag.Bool("n", false,
|
||||||
firstOpt := os.Args[strsId]
|
"Don't add new line character('-N' is lower priority).")
|
||||||
nextLineStr := "\n"
|
newLineStrPtr := flag.String("N", "\n", "Use this instead new line character.")
|
||||||
joinStr := " "
|
joinStrsFlagPtr := flag.Bool("j", false, "Join strings('-J' is lower priority).")
|
||||||
if firstOpt == "-n" {
|
joinStrPtr := flag.String("J", " ", "Use instead of space as separator.")
|
||||||
nextLineStr = ""
|
flag.Parse()
|
||||||
strsId += 1
|
|
||||||
|
if *newLineFlagPtr {
|
||||||
|
*newLineStrPtr = ""
|
||||||
}
|
}
|
||||||
|
if *joinStrsFlagPtr {
|
||||||
|
*joinStrPtr = ""
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("%s%s",
|
fmt.Printf("%s%s",
|
||||||
strings.Join(os.Args[strsId:], joinStr),
|
strings.Join(flag.Args(), *joinStrPtr),
|
||||||
nextLineStr,)
|
*newLineStrPtr,)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue