gobyexample/cli/cli.go

32 lines
730 B
Go
Raw Normal View History

2024-05-04 15:27:54 +00:00
package cli
import (
"flag"
"fmt"
"os"
)
func Cli() {
Args()
Flags()
}
func Args() {
fmt.Println("Program: ", os.Args[0])
fmt.Println("Args:", os.Args[1:])
}
func Flags() {
// NOTE: The flags must come before positional args or else these will take their default values
bookTypePtr := flag.String("booktype", "manga", "The type of book. Valid values are \"manga\", \"comic\", \"fiction\", \"non-fiction\".")
pagesPtr := flag.Uint64("pages", 0, "Number of pages in the book.")
var coverPath string
flag.StringVar(&coverPath, "cover", "", "Path to the cover image of the book.")
flag.Parse()
fmt.Println("Book type:", *bookTypePtr)
fmt.Println("# of Pages:", *pagesPtr)
fmt.Println("Cover path:", coverPath)
}