use of org.apache.nifi.toolkit.cli.api.Session in project nifi by apache.
the class TestCLICompleter method setupCompleter.
@BeforeClass
public static void setupCompleter() {
final Session session = new InMemorySession();
final ClientFactory<NiFiClient> niFiClientFactory = new NiFiClientFactory();
final ClientFactory<NiFiRegistryClient> nifiRegClientFactory = new NiFiRegistryClientFactory();
final Context context = new StandardContext.Builder().output(System.out).session(session).nifiClientFactory(niFiClientFactory).nifiRegistryClientFactory(nifiRegClientFactory).build();
final Map<String, Command> commands = CommandFactory.createTopLevelCommands(context);
final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
completer = new CLICompleter(commands.values(), commandGroups.values());
lineReader = Mockito.mock(LineReader.class);
}
use of org.apache.nifi.toolkit.cli.api.Session in project nifi by apache.
the class AbstractCompositeCommand method createProperties.
/**
* Creates a Properties instance by looking at the propertOption and falling back to the session.
*
* @param commandLine the current command line
* @param propertyOption the options specifying a properties to load
* @param sessionVariable the session variable specifying a properties file
* @return a Properties instance or null if the option wasn't specified and nothing is in the session
*/
private Properties createProperties(final CommandLine commandLine, final CommandOption propertyOption, final SessionVariable sessionVariable) throws IOException, SessionException {
// use the properties file specified by the properyOption if it exists
if (commandLine.hasOption(propertyOption.getLongName())) {
final String propertiesFile = commandLine.getOptionValue(propertyOption.getLongName());
if (!StringUtils.isBlank(propertiesFile)) {
try (final InputStream in = new FileInputStream(propertiesFile)) {
final Properties properties = new Properties();
properties.load(in);
return properties;
}
}
} else {
// no properties file was specified so see if there is anything in the session
if (sessionVariable != null) {
final Session session = getContext().getSession();
final String sessionPropsFiles = session.get(sessionVariable.getVariableName());
if (!StringUtils.isBlank(sessionPropsFiles)) {
try (final InputStream in = new FileInputStream(sessionPropsFiles)) {
final Properties properties = new Properties();
properties.load(in);
return properties;
}
}
}
}
return null;
}
Aggregations