All Projects → frost373 → W2j Cli

frost373 / W2j Cli

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

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to W2j Cli

Hcledit
A command line editor for HCL
Stars: ✭ 104 (-2.8%)
Mutual labels:  cli
Dotfiles
My personal collection of configuration files.
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Fgh
📁 Automate the lifecycle and organization of your cloned GitHub repositories
Stars: ✭ 107 (+0%)
Mutual labels:  cli
Devstats
📊 A CLI application that fetches stats from developer sites
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Schema Registry
A CLI and Go client for Kafka Schema Registry
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Unix Permissions
Swiss Army knife for Unix permissions
Stars: ✭ 106 (-0.93%)
Mutual labels:  cli
Mal
MAL: A MyAnimeList Command Line Interface [BROKEN: BLAME MyAnimeList]
Stars: ✭ 104 (-2.8%)
Mutual labels:  cli
Cliflix
Watch anything instantaneously, just write its name.
Stars: ✭ 1,439 (+1244.86%)
Mutual labels:  cli
Rabbitmq Cli
Command line tools for RabbitMQ
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Glsnip
copy and paste across machines
Stars: ✭ 107 (+0%)
Mutual labels:  cli
Igniteui Cli
Ignite UI Command-Line Interface by Infragistics
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Think Builder
A command line toolit to build applications' CRUD/mvc scaffold for thinkphp v6. 用于生成 thinkphp v6 增查改删脚手架代码的命令行工具。
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+1449.53%)
Mutual labels:  cli
Emplace
👩‍❤️‍💋‍👩 Synchronize installed packages on multiple machines
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Kovid
A CLI to fetch and compare the 2019 coronavirus pandemic statistics. It also fetches historical data and attempts to draw histograms of it to visualise the rate of infections.
Stars: ✭ 107 (+0%)
Mutual labels:  cli
Denox
Script runner and workspace configuration for Deno
Stars: ✭ 105 (-1.87%)
Mutual labels:  cli
Cli.fan
Blog about notable commandline tools
Stars: ✭ 106 (-0.93%)
Mutual labels:  cli
Spinner
Go (golang) package with 90 configurable terminal spinner/progress indicators.
Stars: ✭ 1,637 (+1429.91%)
Mutual labels:  cli
Html Minifier Terser
actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
Stars: ✭ 106 (-0.93%)
Mutual labels:  cli
Force Dev Tool
[DEPRECATED] Command line tool supporting the Force.com development lifecycle
Stars: ✭ 106 (-0.93%)
Mutual labels:  cli

W2J-CLI

JavaWeb Command-line Framework, help you easily build a command line JavaWeb System.
It can be easily combined with any Java framework , and no other dependency.Even you don't need create a HTML page.

Why need it

  • Some functions are provided to professional and do not want to invest in developing front-end.
  • Quick development for a simple management system
  • provided some tools through a web page
  • Quick,simple,fun,geek and so on

Get it

Maven
<!-- 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>
Gradle
// https://mvnrepository.com/artifact/top.thinkin/w2j-cli-core
compile group: 'top.thinkin', name: 'w2j-cli-core', version: '0.1.3'

Some examples

Base

Base input and output,Text-table, Confirm,Auto-Complete

image

create a class and write annotations for root command,commands and parameters

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

Help

Based on you annotations, W2J-CLI could automatically generate the help documents

image

Login

W2J-CLI have provided a built-in login module.

image

This codes simulates a simple logon process

public class YesLogin implements WJLogin<Context> {

    public final static String AUTH = "LX2F8rdCA2wKel9yR42";

    public  String login(String root, String pass, Context context) {
        if("root".equals(root)&&"pass".equals(pass)){
            return View.OK(AUTH);
        }else{
            return View.error("error");
        }
    }

    public  boolean filter(String auth, Context context) {

        if(AUTH.equals(auth)){
            return true;
        }else{
            return false;
        }
    }
}

Use scripts to get more powerful functions

Users can create scripts to achieve stronger functionality. Of course, there are some commonly used built-in scripts.Likes loop command script, you can use it to achieve some animation effects.

/**
     * Circular sending command.
     * The result will be displayed on the screen and overlay the last display.
     * @param cli
     * @param stopPrefix If the prefix is this, the loop will stop
     * @param interval Time interval of a request
     * @return
     */
String script = ScriptKits.LOOP_CLI("task get -id "+id,"ok",500);

image

Getting Started

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

build web.xml

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

build html Servlet

public class HtmlAction extends HttpServlet {
    HTMLConfig config;
    public void init() throws ServletException {
        try {
            // the postUrl is necessary ,if you use built-in login module needLogin must be true
            // there has some other configuration items,you can get them in wiki
            config =  HTMLConfig.cteate().setPostUrl("http://127.0.0.1:8082/api").needLogin(true).build();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.write(config.html());
        writer.close();
    }
}

build the handler Servlet

public class TestAction  extends HttpServlet {
    CommandManage commandManage;
    public void init(){
        try {
            commandManage =  CommandManage.config()
                    .setLogin(new YesLogin()).add(new HelloTest()).add(new TaskTest());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        req.setCharacterEncoding("UTF-8");
        Context context = new Context();//the context of your design
        
        String cli =  req.getParameter("cli");//get the command line
        String auth =  req.getParameter("auth");//get the login authcode
        String x = null;
        try {
            x = commandManage.handleCommand(cli,context,auth);
        } catch (Exception e) {
            e.printStackTrace();
        }
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.write(x);
        writer.close();
    }
}

Prerequisites

JDK 1.6+

Authors

  • Dong Bin - Initial work - BOLG

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

  • Hat tip to anyone who's code was used
  • Inspiration
  • etc
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].