| 1 | // mauflag - An extendable command-line argument parser for Golang |
| 2 | // Copyright (C) 2016 Maunium |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | package mauflagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/ |
| 18 | |
| 19 | import ( |
| 20 | "osscip-go gomod github.com/golang/go/src go1.16 os/" |
| 21 | ) |
| 22 | |
| 23 | var defaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/defaultSet. = Newscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/New().(osscip-go gomod github.com/golang/go/src go1.16 os/.Argsscip-go gomod github.com/golang/go/src go1.16 os/Args.[1:]) |
| 24 | |
| 25 | // DefaultSet returns the default flagset which takes its arguments from os.Args |
| 26 | func DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().() *Setscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set# { |
| 27 | return defaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/defaultSet. |
| 28 | } |
| 29 | |
| 30 | // Make creates and registers a flag |
| 31 | func Makescip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Make().() *Flagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Flag# { |
| 32 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().Makescip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#Make().() |
| 33 | } |
| 34 | |
| 35 | // MakeKey creates and registers a flag with the given short and long keys |
| 36 | func MakeKeyscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/MakeKey().(short, long string) *Flagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Flag# { |
| 37 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().MakeKeyscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#MakeKey().(short, long) |
| 38 | } |
| 39 | |
| 40 | // MakeFull creates and registers a flag with the given short and long keys, usage string and default value |
| 41 | func MakeFullscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/MakeFull().(short, long, usage, defVal string) *Flagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Flag# { |
| 42 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().MakeFullscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#MakeFull().(short, long, usage, defVal) |
| 43 | } |
| 44 | |
| 45 | // Parse the command line arguments into mauflag form |
| 46 | func Parsescip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Parse().() error { |
| 47 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().Parsescip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#Parse().() |
| 48 | } |
| 49 | |
| 50 | // Args returns the arguments that weren't associated with any flag |
| 51 | func Argsscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Args().() []string { |
| 52 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().Argsscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#Args().() |
| 53 | } |
| 54 | |
| 55 | // Arg returns the string at the given index from the list Args() returns |
| 56 | // If the index does not exist, Arg will return an empty string. |
| 57 | func Argscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Arg().(i int) string { |
| 58 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().Argscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#Arg().(i) |
| 59 | } |
| 60 | |
| 61 | // NArg returns the number of arguments not associated with any flags |
| 62 | func NArgscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/NArg().() int { |
| 63 | return len(DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().argsscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#args.) |
| 64 | } |
| 65 | |
| 66 | // MakeHelpFlag creates the -h, --help flag |
| 67 | func MakeHelpFlagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/MakeHelpFlag().() (*bool, *Flagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Flag#) { |
| 68 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().MakeHelpFlagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#MakeHelpFlag().() |
| 69 | } |
| 70 | |
| 71 | // CheckHelpFlag checks if the help flag is set and prints the help page if needed. |
| 72 | // Return value tells whether or not the help page was printed |
| 73 | func CheckHelpFlagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/CheckHelpFlag().() bool { |
| 74 | return DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().CheckHelpFlagscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#CheckHelpFlag().() |
| 75 | } |
| 76 | |
| 77 | // SetHelpTitles sets the first line (program name and basic explanation) and basic usage specification |
| 78 | func SetHelpTitlesscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/SetHelpTitles().(firstLine, basicUsage string) { |
| 79 | DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().SetHelpTitlesscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#SetHelpTitles().(firstLine, basicUsage) |
| 80 | } |
| 81 | |
| 82 | // PrintHelp prints the help page |
| 83 | func PrintHelpscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/PrintHelp().() { |
| 84 | DefaultSetscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/DefaultSet().().PrintHelpscip-go gomod maunium.net/go/mauflag . `maunium.net/go/mauflag`/Set#PrintHelp().() |
| 85 | } |