Created
April 28, 2021 15:56
-
-
Save twolodzko/a97782be0d0bc7b65780df231fc4ea1b to your computer and use it in GitHub Desktop.
Print command line flags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func main() { | |
if len(os.Args) > 1 && os.Args[1] == "--help" { | |
args := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
fmt.Printf("Usage:\n\n%s [--] [%s]...\n\n", os.Args[0], args) | |
out := "Args:\n -- prints space\n" | |
for _, r := range args { | |
ch := string(r) | |
out += fmt.Sprintf(" -%s prints %s\n", ch, ch) | |
} | |
fmt.Print(out) | |
return | |
} | |
var runes []rune | |
for _, arg := range os.Args[1:] { | |
if arg == "--" { | |
runes = append(runes, ' ') | |
continue | |
} | |
for _, r := range arg { | |
if r != '-' { | |
runes = append(runes, r) | |
} | |
} | |
} | |
fmt.Println(string(runes)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment