kandi background
Explore Kits

w2j-cli | JavaWeb CLI Framework , Simple and easy to use | Command Line Interface library

 by   frost373 Java Version: 0.1.3 License: MIT

 by   frost373 Java Version: 0.1.3 License: MIT

Download this library from

kandi X-RAY | w2j-cli Summary

w2j-cli is a Java library typically used in Utilities, Command Line Interface, Framework applications. w2j-cli has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub, Maven.
JavaWeb CLI Framework,Simple and easy to use. 简单易用的Javaweb 命令行框架
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • w2j-cli has a low active ecosystem.
  • It has 106 star(s) with 5 fork(s). There are 23 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 0 open issues and 1 have been closed. On average issues are closed in 323 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of w2j-cli is 0.1.3
w2j-cli Support
Best in #Command Line Interface
Average in #Command Line Interface
w2j-cli Support
Best in #Command Line Interface
Average in #Command Line Interface

quality kandi Quality

  • w2j-cli has 0 bugs and 0 code smells.
w2j-cli Quality
Best in #Command Line Interface
Average in #Command Line Interface
w2j-cli Quality
Best in #Command Line Interface
Average in #Command Line Interface

securitySecurity

  • w2j-cli has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • w2j-cli code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
w2j-cli Security
Best in #Command Line Interface
Average in #Command Line Interface
w2j-cli Security
Best in #Command Line Interface
Average in #Command Line Interface

license License

  • w2j-cli is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
w2j-cli License
Best in #Command Line Interface
Average in #Command Line Interface
w2j-cli License
Best in #Command Line Interface
Average in #Command Line Interface

buildReuse

  • w2j-cli releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
w2j-cli Reuse
Best in #Command Line Interface
Average in #Command Line Interface
w2j-cli Reuse
Best in #Command Line Interface
Average in #Command Line Interface
Top functions reviewed by kandi - BETA

kandi has reviewed w2j-cli and discovered the below as its top functions. This is intended to give you an instant insight into w2j-cli implemented functionality, and help decide if they suit your requirements.

  • Handle a command
    • Normalize path .
      • Converts the table to cells .
        • Builds the css table .
          • To string .
            • Gets the help for a command .
              • Gets a list of files under a given folder .
                • Builds the HTML configuration .
                  • Get prompt arguments
                    • Returns the length of the specified string .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      w2j-cli Key Features

                      JavaWeb CLI Framework,Simple and easy to use. 简单易用的Javaweb 命令行框架

                      Get it

                      copy iconCopydownload iconDownload
                      <!-- https://mvnrepository.com/artifact/top.thinkin/w2j-cli-core -->
                      <dependency>
                          <groupId>top.thinkin</groupId>
                          <artifactId>w2j-cli-core</artifactId>
                          <version>0.1.3</version>
                      </dependency>
                      

                      Some examples

                      copy iconCopydownload iconDownload
                      @HJRoot(name="task",help = "task related operation")
                      public class TaskTest {
                          @HJCommand(name = "list",help = "get the list of task")
                          public String list(
                                  @HJValue(name="start",help = "start time. example:2017-12-1")
                                          String start,
                                  @HJValue(name="end",help = "end time. example:2018-12-1")
                                          String end
                          ) throws WjException {
                              TextTable table =  TextTable.create();
                              table.config("id");
                              table.config("name");
                              table.config("status");
                              table.config("createTime");
                      
                              table.add(Arrays.asList("1","task-1","open","2017-12-1"));
                              table.add(Arrays.asList("2","task-2","open","2017-12-2" ));
                      
                              return View.text(table.buildTable());
                          }
                      
                          @HJCommand(name = "stop",ask = true,help = "stop the task")
                          public String close(
                                  @HJValue(name="id",help = "the task id",req = true)
                                          String id,
                                  @HJContext()
                                          Context context
                      
                          ){
                              return View.text("task is closed");
                          }
                      }
                      

                      Getting Started

                      copy iconCopydownload iconDownload
                      <servlet>
                          <servlet-name>DispatcherServlet</servlet-name>
                          <servlet-class>top.test.web.TestAction</servlet-class>
                          <load-on-startup>1</load-on-startup>
                        </servlet>
                      
                       <servlet>
                          <servlet-name>HtmlServlet</servlet-name>
                          <servlet-class>top.test.web.HtmlAction</servlet-class>
                          <load-on-startup>1</load-on-startup>
                        </servlet>
                       
                        <servlet-mapping>
                          <servlet-name>DispatcherServlet</servlet-name>
                          <url-pattern>/api/*</url-pattern>
                        </servlet-mapping>
                      
                        <servlet-mapping>
                          <servlet-name>HtmlServlet</servlet-name>
                          <url-pattern>/html</url-pattern>
                        </servlet-mapping>
                      

                      Community Discussions

                      Trending Discussions on Command Line Interface
                      • Argparse outputting help text twice
                      • Solving conda environment stuck
                      • Mysql Error while piping database to different server
                      • Shell script to pull row counts from all Hive tables in multiple Hive databases
                      • See workspace in MATLAB command line terminal
                      • How can I fix "Failed to compile src/index.js 'firebase' is not defined no-undef"?
                      • Array of structs only takes last value in C
                      • How to detect if Python is running in Git Bash terminal, or Windows cmd?
                      • Connecting to MySQL server in a script returns error, but it works fine in a terminal
                      • Python 3 + Click: CLI arguments get butchered when calling one command from another
                      Trending Discussions on Command Line Interface

                      QUESTION

                      Argparse outputting help text twice

                      Asked 2022-Feb-25 at 21:44

                      After an hour googling, I can't find anybody who has had anything resembling this issue besides myself. I created a command line interface with argparse. Originally I had tried to leverage argparse's built in help text behavior. But my boss isn't satisfied with the default help text, so he is having me write up the full usage/help text in a text file and just display the entire file.

                      For some reason, in a certain case, its outputting the text twice.

                      Here is the basics of how my program is broken down:

                      I have a top level parser. I read in my help text file, set it to a string help_text, and then set "usage=help_text" on the parser. Then I create subparsers (4 of them and then a base case) to create subcommands. Only one of those subparsers has any additional arguments (one positional, one optional). Before I reworked the help text, I had help text for each individual subcommand by using "help=" but now those are all blank. Lastly, I have set up a base case to display the help text whenever no subcommands are given.

                      Here is the behavior I'm getting:

                      When I call the main function with no subcommands and no arguments, my help_text from the text file outputs, and then like 2-3 additional lines of boiler plate I can't seem to get rid of. Also because the word usage appears in my text file, it says "usage: usage"

                      When I call the main command and then type --help, the exact same thing happens as above.

                      When I call the one subcommand that has a required positional argument and I don't include that argument... it spits out the entire help text twice. Right above the second time it prints, it prints the default usage line for that subcommand.

                      Lastly, when I use a different subcommand that has no arguments and give it an argument (one too many) it spits out everything completely correctly without even the extra couple lines at the end.

                      I don't know how to make heads or tales about this. Here is the main function of the script (I can verify that this problem occurs only in the main function where argparse is used, not the other functions that the main function calls):

                      def main():
                          # Import help text from file
                          p = Path(__file__).with_name("help_text.txt")
                          with p.open() as file:
                              help_text = file.read()
                      
                          # Configure the top level Parser
                          parser = argparse.ArgumentParser(prog='hubmap-clt', description='Name of cli', usage=help_text)
                          subparsers = parser.add_subparsers()
                      
                          # Create Subparsers to give subcommands
                          parser_transfer = subparsers.add_parser('subcommandone')
                          parser_transfer.add_argument('argument1', type=str)
                          parser_transfer.add_argument('--optionalargument', default='mydefault')
                          parser_login = subparsers.add_parser('subcommandtwo')
                          parser_whoami = subparsers.add_parser('subcommandthree')
                          parser_logout = subparsers.add_parser('subcommandfour')
                      
                          # Assign subparsers to their respective functions
                          parser_subcommandone.set_defaults(func=subcommandone)
                          parser_subcommandtwo.set_defaults(func=subcommandtwo)
                          parser_subcommandthree.set_defaults(func=subcommandthree)
                          parser_subcommandfour.set_defaults(func=subcommandfour)
                          parser.set_defaults(func=base_case)
                      
                          # Parse the arguments and call appropriate functions
                          args = parser.parse_args()
                          if len(sys.argv) == 1:
                              args.func(args, parser)
                          else:
                              args.func(args)
                      

                      So to clarify:

                      Why does the extra couple lines of boiler-plat help text appear sometimes which looks like this:

                       name of cli
                      
                       positional arguments:
                           {subcommandone,subcommandtwo,subcommandthree,subcommandfour}
                      
                       optional arguments:
                          -h, --help            show this help message and exit
                      

                      Why does using subcommandone with too few arguments print out the help text twice (but NOT the extra lines of boiler-plate help text.

                      why does using subcommandtwo with one too MANY arguments print everything perfectly without any extra lines?

                      ANSWER

                      Answered 2022-Feb-25 at 21:44

                      With a modification of your main:

                      def foo():
                          # Import help text from file
                          # p = Path(__file__).with_name("help_text.txt")
                          # with p.open() as file:
                          #    help_text = file.read()
                          help_text = "cli usage: foobar\n morebar"
                      
                          # Configure the top level Parser
                          parser = argparse.ArgumentParser(
                              prog="hubmap-clt", description="Name of cli", usage=help_text
                          )
                          subparsers = parser.add_subparsers()
                      
                          # Create Subparsers to give subcommands
                          parser_transfer = subparsers.add_parser("subcommandone")
                          parser_transfer.add_argument("argument1", type=str)
                          parser_transfer.add_argument("--optionalargument", default="mydefault")
                          parser_login = subparsers.add_parser("subcommandtwo")
                          # parser_whoami = subparsers.add_parser("subcommandthree")
                          # parser_logout = subparsers.add_parser("subcommandfour")
                      
                          # Assign subparsers to their respective functions
                          parser_transfer.set_defaults(func="subcommandone")
                          parser_login.set_defaults(func="subcommandtwo")
                          # parser_subcommandthree.set_defaults(func="subcommandthree")
                          # parser_subcommandfour.set_defaults(func="subcommandfour")
                          parser.set_defaults(func="base_case")
                      
                          return parser
                      

                      in an iteractive ipython session:

                      In [8]: p = foo()
                      
                      In [9]: p.print_usage()
                      usage: cli usage: foobar
                       morebar
                      

                      Usage is exactly as I specified. And the help for the main parser:

                      In [10]: p.print_help()
                      usage: cli usage: foobar
                       morebar
                      
                      Name of cli
                      
                      positional arguments:
                        {subcommandone,subcommandtwo}
                      
                      optional arguments:
                        -h, --help            show this help message and exit
                      

                      That's what I expect given the arguments.

                      Help for a subparser:

                      In [11]: p.parse_args(["subcommandone", "-h"])
                      usage: cli usage: foobar
                       morebar subcommandone [-h] [--optionalargument OPTIONALARGUMENT] argument1
                      
                      positional arguments:
                        argument1
                      
                      optional arguments:
                        -h, --help            show this help message and exit
                        --optionalargument OPTIONALARGUMENT
                      

                      Usage is like the main's but with some added info on how to call this subparser and its arguments.

                      Error when calling the subparsers without enough values:

                      In [15]: p.parse_args(["subcommandone"])
                      usage: cli usage: foobar
                       morebar subcommandone [-h] [--optionalargument OPTIONALARGUMENT] argument1
                      cli usage: foobar
                       morebar subcommandone: error: the following arguments are required: argument1
                      

                      Is this repeat of cli usage that bothering you? This error is raised by the subparser, and I suspect the extra comes from the prog of that subparser. I think I saw something like this on the Python bug/issues for argparse.

                      error with too much:

                      In [17]: p.parse_args(["subcommandone", "test", "extra"])
                      usage: cli usage: foobar
                       morebar
                      hubmap-clt: error: unrecognized arguments: extra
                      

                      In this case error is produced by the main parser, hence the "hubmat-clt" prog.

                      change prog:

                      ...: parser_transfer = subparsers.add_parser( ...: "subcommandone", prog="hubmap-clt sobcommandone" ...: )

                      In [21]: p.parse_args(["subcommandone", "test", "extra"])
                      usage: cli usage: foobar
                       morebar
                      hubmap-clt: error: unrecognized arguments: extra
                      
                      In [22]: p.parse_args(["subcommandone"])
                      usage: hubmap-clt sobcommandone [-h] [--optionalargument OPTIONALARGUMENT] argument1
                      hubmap-clt sobcommandone: error: the following arguments are required: argument1
                      

                      [21] is as before [17]. But [22] is now showing the prog that I set. I could also have specified a custom usage for the subparser.

                      If I modify the function to use default usage and prog, but also display the subparser's prog. And I gave the main an "main_foo" positional argument:

                      In [30]: p = foo()
                      hubmap-clt main_foo subcommandone
                      In [31]: p.parse_args(["subcommandone"])
                      Out[31]: Namespace(main_foo='subcommandone')
                      In [32]: p.parse_args(["foo", "subcommandone"])
                      usage: hubmap-clt main_foo subcommandone [-h] [--optionalargument OPTIONALARGUMENT] argument1
                      hubmap-clt main_foo subcommandone: error: the following arguments are required: argument1
                      

                      Notice how the main's usage has been incorporated into the 'prog' for the subparser.

                      In the bug/issue I found the main parser's usage gets incorporated into the prog of the subparser. That's why you see the duplicate.

                      https://bugs.python.org/issue42297 [argparse] Bad error message formatting when using custom usage text

                      The relatively recent date of this bug issue indicates that custom usage is not that common, and even less so when used with subparsers. As my post on this issue indicates, the relation between the main parser, the "subparsers" command, and individual subparsers gets complicated.

                      Source https://stackoverflow.com/questions/71270655

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install w2j-cli

                      W2J-CLI can combined with any Java framework,likes spring,sptingMVC,struts2 and so on. There has a example for combined with base servlet,you can get other ways in wiki.

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Share this Page

                      share link
                      Consider Popular Command Line Interface Libraries
                      Try Top Libraries by frost373
                      Compare Command Line Interface Libraries with Highest Support
                      Compare Command Line Interface Libraries with Highest Quality
                      Compare Command Line Interface Libraries with Highest Security
                      Compare Command Line Interface Libraries with Permissive License
                      Compare Command Line Interface Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.