From 264780bb60dda33e8d06c48be5f1991212d62a9a Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 5 Dec 2023 01:32:52 +0100 Subject: Replace ‘optind’ with ‘rest’ in Get() and GetLong() returns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index b15aaf4..34e26d9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +## Update 6th December, 2023 + +The v2 of this library has been released, and you should probably use +that instead: + +```sh +$ go get -u git.sr.ht/~mango/opts/v2 +``` + # Opts Opts is a simple Go library implementing unicode-aware getopt(3)- and @@ -21,7 +30,7 @@ import ( "fmt" "os" - "git.sr.ht/~mango/opts" + "git.sr.ht/~mango/opts/v2" ) func usage() { @@ -30,7 +39,7 @@ func usage() { } func main() { - flags, optind, err := opts.Get(os.Args, "a:ßλ") + flags, rest, err := opts.Get(os.Args, "a:ßλ") if err != nil { fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err) usage() @@ -47,8 +56,7 @@ func main() { } } - // The remaining arguments - rest := os.Args[optind:] + fmt.Println("The remaining arguments are:", rest) } ``` @@ -65,19 +73,18 @@ import ( "git.sr.ht/~mango/opts" ) -const noShortFlag = -1 - func usage() { fmt.Fprintf(os.Stderr, "Usage: %s [-ßλ] [-a arg] [--no-short]\n", os.Args[0]) os.Exit(1) } func main() { - flags, optind, err := opts.GetLong(os.Args, []opts.LongOpt{ + // The fourth long-option has no short-option equivalent + flags, rest, err := opts.GetLong(os.Args, []opts.LongOpt{ {Short: 'a', Long: "add", Arg: opts.Required}, {Short: 'ß', Long: "sheiße", Arg: opts.None}, {Short: 'λ', Long: "λεωνίδας", Arg: opts.None}, - {Short: noShortFlag, Long: "no-short", Arg: opts.None}, + {Short: -1, Long: "no-short", Arg: opts.None}, }) if err != nil { fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err) @@ -92,12 +99,12 @@ func main() { fmt.Println("-ß or --sheiße given") case 'λ': fmt.Println("-λ or --λεωνίδας given") - case noShortFlag: + case -1: fmt.Println("--no-short given") } } // The remaining arguments - rest := os.Args[optind:] + fmt.Println("The remaining arguments are:", rest) } ``` -- cgit v1.2.3