How to recieve a string of sentence using click.option() in Python?

Multi tool use
I am trying to create a simple command line interface to maintain todo tasks.
Now I know that I can use click.argument()
to get a string sentence from user but I want to have similar functionality using click.option()
.
@click.command()
@click.option('-a', '--add', type=click.STRING, help='Task you want to add')
@click.option('-rm', '--remove', type=click.INT, help='ID of task you want to remove')
def cli(add, remove):
if add:
add_task(add)
elif remove:
remove_task(remove)
else:
list()
As per the above script:todo -a Hello World !!
Only gets the string "Hello", however I want the complete sentence.
python python-3.x click command-line-interface
add a comment |
I am trying to create a simple command line interface to maintain todo tasks.
Now I know that I can use click.argument()
to get a string sentence from user but I want to have similar functionality using click.option()
.
@click.command()
@click.option('-a', '--add', type=click.STRING, help='Task you want to add')
@click.option('-rm', '--remove', type=click.INT, help='ID of task you want to remove')
def cli(add, remove):
if add:
add_task(add)
elif remove:
remove_task(remove)
else:
list()
As per the above script:todo -a Hello World !!
Only gets the string "Hello", however I want the complete sentence.
python python-3.x click command-line-interface
add a comment |
I am trying to create a simple command line interface to maintain todo tasks.
Now I know that I can use click.argument()
to get a string sentence from user but I want to have similar functionality using click.option()
.
@click.command()
@click.option('-a', '--add', type=click.STRING, help='Task you want to add')
@click.option('-rm', '--remove', type=click.INT, help='ID of task you want to remove')
def cli(add, remove):
if add:
add_task(add)
elif remove:
remove_task(remove)
else:
list()
As per the above script:todo -a Hello World !!
Only gets the string "Hello", however I want the complete sentence.
python python-3.x click command-line-interface
I am trying to create a simple command line interface to maintain todo tasks.
Now I know that I can use click.argument()
to get a string sentence from user but I want to have similar functionality using click.option()
.
@click.command()
@click.option('-a', '--add', type=click.STRING, help='Task you want to add')
@click.option('-rm', '--remove', type=click.INT, help='ID of task you want to remove')
def cli(add, remove):
if add:
add_task(add)
elif remove:
remove_task(remove)
else:
list()
As per the above script:todo -a Hello World !!
Only gets the string "Hello", however I want the complete sentence.
python python-3.x click command-line-interface
python python-3.x click command-line-interface
asked Jan 1 at 9:12
adzo261adzo261
103
103
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
according to the docs, all you need to do is add nargs=<the number you want>
for example:
@click.option('-a', '--add',nargs=2, type=click.STRING, help='Task you want to add')
or you can always run you script like that:
todo --add="Hello World !!"
But to specifynargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.
– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use-a STRING
as it looks clean?
– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
add a comment |
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%2f53994255%2fhow-to-recieve-a-string-of-sentence-using-click-option-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
according to the docs, all you need to do is add nargs=<the number you want>
for example:
@click.option('-a', '--add',nargs=2, type=click.STRING, help='Task you want to add')
or you can always run you script like that:
todo --add="Hello World !!"
But to specifynargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.
– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use-a STRING
as it looks clean?
– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
add a comment |
according to the docs, all you need to do is add nargs=<the number you want>
for example:
@click.option('-a', '--add',nargs=2, type=click.STRING, help='Task you want to add')
or you can always run you script like that:
todo --add="Hello World !!"
But to specifynargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.
– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use-a STRING
as it looks clean?
– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
add a comment |
according to the docs, all you need to do is add nargs=<the number you want>
for example:
@click.option('-a', '--add',nargs=2, type=click.STRING, help='Task you want to add')
or you can always run you script like that:
todo --add="Hello World !!"
according to the docs, all you need to do is add nargs=<the number you want>
for example:
@click.option('-a', '--add',nargs=2, type=click.STRING, help='Task you want to add')
or you can always run you script like that:
todo --add="Hello World !!"
answered Jan 1 at 9:21
ddor254ddor254
988519
988519
But to specifynargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.
– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use-a STRING
as it looks clean?
– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
add a comment |
But to specifynargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.
– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use-a STRING
as it looks clean?
– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
But to specify
nargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.– adzo261
Jan 1 at 9:24
But to specify
nargs
I need to know the number of string words beforehand.This is not my use case. I want to receive string of any word length.– adzo261
Jan 1 at 9:24
so use the second option i suggested
– ddor254
Jan 1 at 9:26
so use the second option i suggested
– ddor254
Jan 1 at 9:26
Okay, I will use that, but isn't there a way to use
-a STRING
as it looks clean?– adzo261
Jan 1 at 9:29
Okay, I will use that, but isn't there a way to use
-a STRING
as it looks clean?– adzo261
Jan 1 at 9:29
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
I can check in a few minutes, and get back to you, but if the second option solved your problem please upvote and accept :)
– ddor254
Jan 1 at 9:34
add a comment |
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%2f53994255%2fhow-to-recieve-a-string-of-sentence-using-click-option-in-python%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
wPiMkmNq,wHlrpJ3pAqO6nM,WsC