Add cli
This commit is contained in:
31
cli/cli.go
Normal file
31
cli/cli.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user