-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c83ca56
commit f6f46c4
Showing
5 changed files
with
231 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package getoptions | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/DavidGamba/go-getoptions/text" | ||
) | ||
|
||
// GetRequiredArg - Get the next argument from the args list and error if it doesn't exist. | ||
// By default the error will include the HelpSynopsis section but it can be overriden with the list of sections or getoptions.HelpNone. | ||
// | ||
// If the arguments have been named with `opt.HelpSynopsisArg` then the error will include the argument name. | ||
func (gopt *GetOpt) GetRequiredArg(args []string, sections ...HelpSection) (string, []string, error) { | ||
if len(args) < 1 { | ||
if len(gopt.programTree.SynopsisArgs) > gopt.programTree.SynopsisArgsIdx { | ||
argName := gopt.programTree.SynopsisArgs[gopt.programTree.SynopsisArgsIdx].Arg | ||
fmt.Fprintf(Writer, text.ErrorMissingRequiredNamedArgument+"\n", argName) | ||
} else { | ||
fmt.Fprintf(Writer, "%s\n", text.ErrorMissingRequiredArgument) | ||
} | ||
if sections != nil { | ||
fmt.Fprintf(Writer, "%s", gopt.Help(sections...)) | ||
} else { | ||
fmt.Fprintf(Writer, "%s", gopt.Help(HelpSynopsis)) | ||
} | ||
gopt.programTree.SynopsisArgsIdx++ | ||
return "", args, ErrorHelpCalled | ||
} | ||
gopt.programTree.SynopsisArgsIdx++ | ||
return args[0], args[1:], nil | ||
} |
This file contains 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
This file contains 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
This file contains 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