Last active
October 1, 2024 01:41
-
-
Save maciakl/b5877bcb8b1ad21e2e798d3da3bff13b to your computer and use it in GitHub Desktop.
Hello World in Go
This file contains hidden or 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 ( | |
"os" | |
"fmt" | |
"path/filepath" | |
) | |
const version = "0.1.0" | |
func main() { | |
if len(os.Args) > 1 { | |
switch os.Args[1] { | |
case "-v", "--version": | |
Version() | |
case "-h", "--help": | |
Usage() | |
default: | |
Usage() | |
} | |
} else { | |
Usage() | |
} | |
} | |
func Version() { | |
fmt.Println(filepath.Base(os.Args[0]), "version", version) | |
os.Exit(0) | |
} | |
func Usage() { | |
fmt.Println("Usage:", filepath.Base(os.Args[0]), "[options]") | |
fmt.Println("Options:") | |
fmt.Println(" -v, --version Print version information and exit") | |
fmt.Println(" -h, --help Print this message and exit") | |
os.Exit(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment