Browse Source

增加启动参数,设置使用的Console

tags/1.1.0
shaozhuguang 5 years ago
parent
commit
06fe31e836
3 changed files with 44 additions and 6 deletions
  1. +1
    -1
      source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh
  2. +13
    -5
      source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java
  3. +30
    -0
      source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/PresetAnswerPrompter.java

+ 1
- 1
source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh View File

@@ -1,7 +1,7 @@
#!/bin/bash

HOME=$(cd `dirname $0`;cd ../; pwd)
boot_file=$(ls ../libs | grep tools-initializer-booter-)
boot_file=$(ls $HOME/libs | grep tools-initializer-booter-)
if [ ! -n "$boot_file" ]; then
echo "tools-initializer-booter is null"
else


+ 13
- 5
source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java View File

@@ -46,8 +46,12 @@ public class LedgerInitCommand {
// 是否输出调试信息;
private static final String DEBUG_OPT = "-debug";

private static final String MONITOR_OPT = "-monitor";

private static final Prompter DEFAULT_PROMPTER = new ConsolePrompter();

private static final Prompter ANSWER_PROMPTER = new PresetAnswerPrompter("Y");

/**
* 入口;
*
@@ -56,18 +60,22 @@ public class LedgerInitCommand {
public static void main(String[] args) {
Prompter prompter = DEFAULT_PROMPTER;

Setting argSetting = ArgumentSet.setting().prefix(LOCAL_ARG, INI_ARG).option(DEBUG_OPT);
ArgumentSet argset = ArgumentSet.resolve(args, argSetting);
Setting argSetting = ArgumentSet.setting().prefix(LOCAL_ARG, INI_ARG).option(DEBUG_OPT).option(MONITOR_OPT);
ArgumentSet argSet = ArgumentSet.resolve(args, argSetting);

try {
ArgEntry localArg = argset.getArg(LOCAL_ARG);
if (argSet.hasOption(MONITOR_OPT)) {
prompter = ANSWER_PROMPTER;
}

ArgEntry localArg = argSet.getArg(LOCAL_ARG);
if (localArg == null) {
prompter.info("Miss local config file which can be specified with arg [%s]!!!", LOCAL_ARG);

}
LocalConfig localConf = LocalConfig.resolve(localArg.getValue());

ArgEntry iniArg = argset.getArg(INI_ARG);
ArgEntry iniArg = argSet.getArg(INI_ARG);
if (iniArg == null) {
prompter.info("Miss ledger initializing config file which can be specified with arg [%s]!!!", INI_ARG);
return;
@@ -135,7 +143,7 @@ public class LedgerInitCommand {

} catch (Exception e) {
prompter.error("\r\nError!! -- %s\r\n", e.getMessage());
if (argset.hasOption(DEBUG_OPT)) {
if (argSet.hasOption(DEBUG_OPT)) {
e.printStackTrace();
}



+ 30
- 0
source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/PresetAnswerPrompter.java View File

@@ -0,0 +1,30 @@
package com.jd.blockchain.tools.initializer;

import java.util.Properties;

public class PresetAnswerPrompter extends ConsolePrompter {

private Properties answers = new Properties();

private String defaultAnswer;

public PresetAnswerPrompter(String defaultAnswer) {
this.defaultAnswer = defaultAnswer;
}

public void setAnswer(String tag, String answer) {
answers.setProperty(tag, answer);
}

public void setDefaultAnswer(String defaultAnswer) {
this.defaultAnswer = defaultAnswer;
}

@Override
public String confirm(String tag, String format, Object... args) {
System.out.print(String.format(format, args));
String answer = answers.getProperty(tag, defaultAnswer);
System.out.println(String.format("\r\n [Default answer:%s]", answer));
return answer;
}
}

Loading…
Cancel
Save