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

Multi tool use
Multi tool use












0















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.










share|improve this question



























    0















    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.










    share|improve this question

























      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 9:12









      adzo261adzo261

      103




      103
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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 !!"






          share|improve this answer
























          • 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











          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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 !!"






          share|improve this answer
























          • 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











          • 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
















          0














          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 !!"






          share|improve this answer
























          • 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











          • 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














          0












          0








          0







          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 !!"






          share|improve this answer













          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 !!"







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 9:21









          ddor254ddor254

          988519




          988519













          • 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











          • 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













          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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
          RW8 55xnz3fEb71Dk0VOAjFTGsjx8shYjytuIZ 14K0AlQx,y x1 RfOlDLpwjjaIMHZGIgF 41MrV2HXv Po8T QoQCEx

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas