Skip to content

Commit

Permalink
feat: SystemEnv command support sort option #alibaba#2619
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondLam1 committed Sep 5, 2023
1 parent f6351cb commit 66769b5
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,48 @@
import com.taobao.middleware.cli.annotations.Argument;
import com.taobao.middleware.cli.annotations.Description;
import com.taobao.middleware.cli.annotations.Name;
import com.taobao.middleware.cli.annotations.Option;
import com.taobao.middleware.cli.annotations.Summary;

import java.util.Map;
import java.util.TreeMap;

/**
* @author hengyunabc 2018-11-09
*
*/
@Name("sysenv")
@Summary("Display the system env.")
@Description(Constants.EXAMPLE + " sysenv\n" + " sysenv USER\n" + Constants.WIKI + Constants.WIKI_HOME + "sysenv")
public class SystemEnvCommand extends AnnotatedCommand {

private String envName;
private boolean sorted;

@Argument(index = 0, argName = "env-name", required = false)
@Description("env name")
public void setOptionName(String envName) {
this.envName = envName;
}

@Option(shortName = "s", longName = "sort")
@Description("view all sorted system env ")
public void setHashCode(boolean sorted) {
this.sorted = sorted;
}

@Override
public void process(CommandProcess process) {
try {
SystemEnvModel result = new SystemEnvModel();
if (StringUtils.isBlank(envName)) {
// show all system env
result.putAll(System.getenv());
Map<String, String> res = null;
if (sorted) {
res = new TreeMap<>(System.getenv());
} else {
res = System.getenv();
}
result.putAll(res);
} else {
// view the specified system env
String value = System.getenv(envName);
Expand All @@ -52,8 +68,7 @@ public void process(CommandProcess process) {
* First, try to complete with the sysenv command scope. If completion is
* failed, delegates to super class.
*
* @param completion
* the completion object
* @param completion the completion object
*/
@Override
public void complete(Completion completion) {
Expand Down

0 comments on commit 66769b5

Please sign in to comment.