Python argparse help option in a mutually_exclusive_group
The argparse
module for Python 2.7 includes a command line help option, that by default prints a usage message whenever -h
or --help
is present in the command line options. By default, the help option can be passed in with any other command line options. For example:
script.py [-h] [-opt1 arg1 | -opt2 arg2]
If the -h
optional argument exists, all other args are ignored and the help message is printed.
Is there a way to change this behavior so that -h
has to be used alone, like can be done with any other optional arg by placing it within a mutually_exclusive_group
?
python python-2.7 argparse
|
show 2 more comments
The argparse
module for Python 2.7 includes a command line help option, that by default prints a usage message whenever -h
or --help
is present in the command line options. By default, the help option can be passed in with any other command line options. For example:
script.py [-h] [-opt1 arg1 | -opt2 arg2]
If the -h
optional argument exists, all other args are ignored and the help message is printed.
Is there a way to change this behavior so that -h
has to be used alone, like can be done with any other optional arg by placing it within a mutually_exclusive_group
?
python python-2.7 argparse
2
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
My thoughts too haha. Well you can setadd_help
toFalse
and define your own process with the-h
flag.
– busybear
Dec 29 '18 at 19:36
@busybear I see theadd_help=False
parameter in the docs now. Thanks. To me, it seems consistent that-h
should be used alone, but as Kenny pointed out, it's kind of a moot point!
– Matt P
Dec 29 '18 at 19:44
1
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08
|
show 2 more comments
The argparse
module for Python 2.7 includes a command line help option, that by default prints a usage message whenever -h
or --help
is present in the command line options. By default, the help option can be passed in with any other command line options. For example:
script.py [-h] [-opt1 arg1 | -opt2 arg2]
If the -h
optional argument exists, all other args are ignored and the help message is printed.
Is there a way to change this behavior so that -h
has to be used alone, like can be done with any other optional arg by placing it within a mutually_exclusive_group
?
python python-2.7 argparse
The argparse
module for Python 2.7 includes a command line help option, that by default prints a usage message whenever -h
or --help
is present in the command line options. By default, the help option can be passed in with any other command line options. For example:
script.py [-h] [-opt1 arg1 | -opt2 arg2]
If the -h
optional argument exists, all other args are ignored and the help message is printed.
Is there a way to change this behavior so that -h
has to be used alone, like can be done with any other optional arg by placing it within a mutually_exclusive_group
?
python python-2.7 argparse
python python-2.7 argparse
asked Dec 29 '18 at 18:11
Matt PMatt P
1,4491619
1,4491619
2
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
My thoughts too haha. Well you can setadd_help
toFalse
and define your own process with the-h
flag.
– busybear
Dec 29 '18 at 19:36
@busybear I see theadd_help=False
parameter in the docs now. Thanks. To me, it seems consistent that-h
should be used alone, but as Kenny pointed out, it's kind of a moot point!
– Matt P
Dec 29 '18 at 19:44
1
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08
|
show 2 more comments
2
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
My thoughts too haha. Well you can setadd_help
toFalse
and define your own process with the-h
flag.
– busybear
Dec 29 '18 at 19:36
@busybear I see theadd_help=False
parameter in the docs now. Thanks. To me, it seems consistent that-h
should be used alone, but as Kenny pointed out, it's kind of a moot point!
– Matt P
Dec 29 '18 at 19:44
1
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08
2
2
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
My thoughts too haha. Well you can set
add_help
to False
and define your own process with the -h
flag.– busybear
Dec 29 '18 at 19:36
My thoughts too haha. Well you can set
add_help
to False
and define your own process with the -h
flag.– busybear
Dec 29 '18 at 19:36
@busybear I see the
add_help=False
parameter in the docs now. Thanks. To me, it seems consistent that -h
should be used alone, but as Kenny pointed out, it's kind of a moot point!– Matt P
Dec 29 '18 at 19:44
@busybear I see the
add_help=False
parameter in the docs now. Thanks. To me, it seems consistent that -h
should be used alone, but as Kenny pointed out, it's kind of a moot point!– Matt P
Dec 29 '18 at 19:44
1
1
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972135%2fpython-argparse-help-option-in-a-mutually-exclusive-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972135%2fpython-argparse-help-option-in-a-mutually-exclusive-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Just out of curiosity, what will you do if they violate this constraint? Print the help? :)
– Kenny Ostrom
Dec 29 '18 at 19:20
@KennyOstrom That is ...(wince)... probably the most logical thing to do. Hmm.
– Matt P
Dec 29 '18 at 19:33
My thoughts too haha. Well you can set
add_help
toFalse
and define your own process with the-h
flag.– busybear
Dec 29 '18 at 19:36
@busybear I see the
add_help=False
parameter in the docs now. Thanks. To me, it seems consistent that-h
should be used alone, but as Kenny pointed out, it's kind of a moot point!– Matt P
Dec 29 '18 at 19:44
1
Imagine your user starts writing a command line and then has some sort of question or unknown. They can add a '-h' to bailout and ask for help. No need to delete all the previous strings. The help request has priority regardless of how much they've written so far. This behavior is somewhat modified when using subparsers.
– hpaulj
Dec 29 '18 at 23:08