提交修改
This commit is contained in:
parent
55199060d9
commit
eae74ff36c
@ -45,6 +45,8 @@ public class Option {
|
|||||||
*/
|
*/
|
||||||
protected String longName = NO_NAME;
|
protected String longName = NO_NAME;
|
||||||
|
|
||||||
|
protected int index = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the option short name.
|
* the option short name.
|
||||||
*/
|
*/
|
||||||
@ -428,4 +430,14 @@ public class Option {
|
|||||||
this.choices.add(choice);
|
this.choices.add(choice);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/main/java/com/lz/modules/command/OptionComparator.java
Normal file
16
src/main/java/com/lz/modules/command/OptionComparator.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.lz.modules.command;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class OptionComparator implements Comparator<Option> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Option o1, Option o2) {
|
||||||
|
if (o1.getIndex() == o2.getIndex()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.lz.modules.command.annotation;
|
package com.lz.modules.command.annotation;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@ -32,6 +34,7 @@ import java.lang.annotation.Target;
|
|||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Option {
|
public @interface Option {
|
||||||
|
int index () default 0;
|
||||||
|
|
||||||
String NO_NAME = "\0";
|
String NO_NAME = "\0";
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import com.lz.modules.command.BaseCommand;
|
|||||||
import com.lz.modules.command.ICommand;
|
import com.lz.modules.command.ICommand;
|
||||||
import com.lz.modules.command.annotation.Description;
|
import com.lz.modules.command.annotation.Description;
|
||||||
import com.lz.modules.command.annotation.Name;
|
import com.lz.modules.command.annotation.Name;
|
||||||
|
import com.lz.modules.command.annotation.Option;
|
||||||
import com.lz.modules.command.annotation.Summary;
|
import com.lz.modules.command.annotation.Summary;
|
||||||
import com.lz.modules.sys.entity.SysUserEntity;
|
import com.lz.modules.sys.entity.SysUserEntity;
|
||||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||||
@ -21,7 +22,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Component("record")
|
@Component("record")
|
||||||
@Name("record")
|
@Name("record")
|
||||||
@Summary("绩效")
|
@Summary("查看绩效列表")
|
||||||
@Description(value = Constant.EXAMPLE +
|
@Description(value = Constant.EXAMPLE +
|
||||||
" record list \n"
|
" record list \n"
|
||||||
)
|
)
|
||||||
@ -64,8 +65,10 @@ public class RecordCommand extends BaseCommand implements ICommand<Tuple> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Option(shortName = "list")
|
||||||
|
@Description("绩效列表")
|
||||||
|
public void setL(String l) {
|
||||||
|
this.l = l;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
package com.lz.modules.command.base1000;
|
package com.lz.modules.command.base1000;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.lz.common.utils.Constant;
|
import com.lz.common.utils.*;
|
||||||
import com.lz.common.utils.NumberUtil;
|
|
||||||
import com.lz.common.utils.R;
|
|
||||||
import com.lz.common.utils.StringUtil;
|
|
||||||
import com.lz.modules.app.dto.ResultDto;
|
import com.lz.modules.app.dto.ResultDto;
|
||||||
import com.lz.modules.app.utils.t.Tuple;
|
import com.lz.modules.app.utils.t.Tuple;
|
||||||
import com.lz.modules.app.utils.t.TwoTuple;
|
import com.lz.modules.app.utils.t.TwoTuple;
|
||||||
import com.lz.modules.command.BaseCommand;
|
import com.lz.modules.command.BaseCommand;
|
||||||
import com.lz.modules.command.ICommand;
|
import com.lz.modules.command.ICommand;
|
||||||
import com.lz.modules.command.annotation.*;
|
import com.lz.modules.command.annotation.*;
|
||||||
|
import com.lz.modules.command.utils.CLI;
|
||||||
|
import com.lz.modules.command.utils.CLIConfigurator;
|
||||||
import com.lz.modules.flow.model.TaskDto;
|
import com.lz.modules.flow.model.TaskDto;
|
||||||
import com.lz.modules.performance.service.ResultTaskService;
|
import com.lz.modules.performance.service.ResultTaskService;
|
||||||
import com.lz.modules.sys.entity.SysUserEntity;
|
import com.lz.modules.sys.entity.SysUserEntity;
|
||||||
@ -20,11 +19,12 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.sound.midi.Soundbank;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component("task")
|
@Component("task")
|
||||||
@Name("task")
|
@Name("task")
|
||||||
@Summary("绩效任务添加更新 ")
|
@Summary("绩效任务查看 添加 或 更新 ")
|
||||||
@Description(Constant.EXAMPLE +
|
@Description(Constant.EXAMPLE +
|
||||||
" task add 1 \"短信开发\"\n" +
|
" task add 1 \"短信开发\"\n" +
|
||||||
" task add 1 \"短信开发\" 30 \n" +
|
" task add 1 \"短信开发\" 30 \n" +
|
||||||
@ -180,37 +180,41 @@ public class TaskCommand extends BaseCommand implements ICommand<Tuple> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Argument(index = 0, argName = "option")
|
@Option(index = 0,shortName = "o")
|
||||||
@Option(shortName = "o")
|
|
||||||
@Description("任务操作")
|
@Description("任务操作")
|
||||||
public void setOption(String option) {
|
public void setOption(String option) {
|
||||||
this.option = option;
|
this.option = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(shortName = "id")
|
@Option(index = 1,shortName = "id")
|
||||||
@Description("任务 id")
|
@Description("任务 id")
|
||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(shortName = "n")
|
@Option(index = 2,shortName = "n")
|
||||||
@Description("任务名称")
|
@Description("任务名称")
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(shortName = "r")
|
|
||||||
|
@Option(index = 3,shortName = "r")
|
||||||
@Description("任务进度")
|
@Description("任务进度")
|
||||||
public void setRate(String rate) {
|
public void setRate(String rate) {
|
||||||
this.rate = rate;
|
this.rate = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(shortName = "m")
|
@Option(index = 4,shortName = "m")
|
||||||
@Description("任务说明")
|
@Description("任务说明")
|
||||||
public void setMark(String mark) {
|
public void setMark(String mark) {
|
||||||
this.mark = mark;
|
this.mark = mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CLI cli = CLIConfigurator.define(TaskCommand.class);
|
||||||
|
System.out.println(JSON.toJSONString(cli));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ package com.lz.modules.command.utils;
|
|||||||
|
|
||||||
|
|
||||||
import com.lz.modules.command.ArgumentComparator;
|
import com.lz.modules.command.ArgumentComparator;
|
||||||
|
import com.lz.modules.command.OptionComparator;
|
||||||
import com.lz.modules.command.TypedArgument;
|
import com.lz.modules.command.TypedArgument;
|
||||||
import com.lz.modules.command.TypedOption;
|
import com.lz.modules.command.TypedOption;
|
||||||
import com.lz.modules.command.annotation.*;
|
import com.lz.modules.command.annotation.*;
|
||||||
@ -91,6 +92,8 @@ public class CLIConfigurator {
|
|||||||
}
|
}
|
||||||
// Sort the argument by index.
|
// Sort the argument by index.
|
||||||
Collections.sort(cli.getArguments(), new ArgumentComparator());
|
Collections.sort(cli.getArguments(), new ArgumentComparator());
|
||||||
|
|
||||||
|
Collections.sort(cli.getOptions(), new OptionComparator());
|
||||||
return cli;
|
return cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +110,8 @@ public class CLIConfigurator {
|
|||||||
.setArgName(option.argName())
|
.setArgName(option.argName())
|
||||||
.setFlag(option.flag())
|
.setFlag(option.flag())
|
||||||
.setHelp(option.help())
|
.setHelp(option.help())
|
||||||
.setRequired(option.required());
|
.setRequired(option.required())
|
||||||
|
.setIndex(option.index());
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
Description description = method.getAnnotation(Description.class);
|
Description description = method.getAnnotation(Description.class);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user