org.springframework.shell.CommandLine Java Examples

The following examples show how to use org.springframework.shell.CommandLine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShellCommandLineParser.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
/**
 * Parse {@link ShellProperties} and {@link ApplicationArguments} to create an instance of the
 * @param shellProperties the shell properties
 * @param applicationArguments the raw unprocessed arguments that were passed to the application.
 * @return a new {@link CommandLine} instance.
 */
public CommandLine parse(ShellProperties shellProperties, String[] applicationArguments) {
    List<String> commands = new ArrayList<String>();
    if (shellProperties.getCommandFile() != null) {
            File f = new File(shellProperties.getCommandFile());
            try {
                commands.addAll(FileUtils.readLines(f));
            } catch (IOException e) {
                logger.error("Unable to read from " + f.toString(), e);
            }
    }
    String[] commandsToExecute = (commands.size() > 0) ? commands.toArray(new String[commands.size()]) : null;

    int historySize = shellProperties.getHistorySize();
    if (historySize < 0) {
        logger.warn("historySize option must be > 0, using default value of " +
                SimpleShellCommandLineOptions.DEFAULT_HISTORY_SIZE);
        historySize = SimpleShellCommandLineOptions.DEFAULT_HISTORY_SIZE;
    }

    return new CommandLine(applicationArguments, historySize, commandsToExecute);
}
 
Example #2
Source File: ConfigCommandTests.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	MockitoAnnotations.initMocks(this);

	final CommandLine commandLine = Mockito.mock(CommandLine.class);

	when(commandLine.getArgs()).thenReturn(null);

	final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
	messageConverters.add(new  MappingJackson2HttpMessageConverter());

	when(restTemplate.getMessageConverters()).thenReturn(messageConverters);
	final Exception e = new RestClientException("FooBar");
	when(restTemplate.getForObject(Mockito.any(URI.class), Mockito.eq(ResourceSupport.class))).thenThrow(e);

	configCommands.setTargetHolder(new TargetHolder());
	configCommands.setRestTemplate(restTemplate);
	configCommands.setDataFlowShell(dataFlowShell);
	configCommands.setServerUri("http://localhost:9393");
	configCommands.onApplicationEvent(null);
}
 
Example #3
Source File: ShellCommandLineParser.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Parse {@link ShellProperties} and {@link ApplicationArguments} to create an
 * instance of the
 *
 * @param shellProperties the shell properties
 * @param applicationArguments the raw unprocessed arguments that were passed to the
 * application.
 * @return a new {@link CommandLine} instance.
 */
public CommandLine parse(ShellProperties shellProperties, String[] applicationArguments) {
	List<String> commands = new ArrayList<String>();
	if (shellProperties.getCommandFile() != null) {
		for (String filePath : shellProperties.getCommandFile()) {
			File f = new File(filePath);
			try {
				commands.addAll(FileUtils.readLines(f));
			}
			catch (IOException e) {
				logger.error("Unable to read from " + f.toString(), e);
			}
		}
	}
	String[] commandsToExecute = (commands.size() > 0) ? commands.toArray(new String[commands.size()]) : null;

	int historySize = shellProperties.getHistorySize();
	if (historySize < 0) {
		logger.warn("historySize option must be > 0, using default value of "
				+ SimpleShellCommandLineOptions.DEFAULT_HISTORY_SIZE);
		historySize = SimpleShellCommandLineOptions.DEFAULT_HISTORY_SIZE;
	}

	return new CommandLine(applicationArguments, historySize, commandsToExecute);
}
 
Example #4
Source File: ConfigCommandTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	final CommandLine commandLine = Mockito.mock(CommandLine.class);

	when(commandLine.getArgs()).thenReturn(null);

	final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
	messageConverters.add(new MappingJackson2HttpMessageConverter());

	when(restTemplate.getMessageConverters()).thenReturn(messageConverters);

	TargetHolder targetHolder = new TargetHolder();
	targetHolder.setTarget(new Target("http://localhost:9393"));
	configCommands.setTargetHolder(targetHolder);
	configCommands.setRestTemplate(restTemplate);
	configCommands.setDataFlowShell(dataFlowShell);
	configCommands.setServerUri("http://localhost:9393");
}
 
Example #5
Source File: BaseShellAutoConfiguration.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(CommandLine.class)
public CommandLine commandLine(ShellCommandLineParser shellCommandLineParser,
							ShellProperties shellProperties,
							ApplicationArguments applicationArguments) throws Exception {
	return shellCommandLineParser.parse(shellProperties, applicationArguments.getSourceArgs());
}
 
Example #6
Source File: BaseShellAutoConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(CommandLine.class)
public CommandLine commandLine(ShellCommandLineParser shellCommandLineParser, ShellProperties shellProperties,
		ApplicationArguments applicationArguments) throws Exception {
	return shellCommandLineParser.parse(shellProperties, applicationArguments.getSourceArgs());
}
 
Example #7
Source File: ShellConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
CommandLine commandLine() throws Exception {
  String[] args = cmdFile.length() > 0 ? new String[]{"--cmdfile", cmdFile} : new String[0];
  return SimpleShellCommandLineOptions.parseCommandLine(args);
}