String autoCompleteScript = bash(scriptName, commandLine); Writer completionWriter = null; Writer scriptWriter = null;
private void generateAutoCompleteScript() { System.out.println(AutoComplete.bash("git", mainCommand())); }
AutoComplete.bash(commandName, autoCompleteScript, commandScript, commandLine); return EXIT_CODE_SUCCESS;
@Test public void testBashRejectsNullCommandLine() { try { AutoComplete.bash("script", null); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals("commandLine", ok.getMessage()); } }
@Test public void testBooleanArgFilter() { @Command(name = "booltest") class App { @Option(names = "-b") boolean primitive; @Option(names = "-B") Boolean object; } String actual = AutoComplete.bash("booltest", new CommandLine(new App())); assertThat(actual, CoreMatchers.containsString("FLAG_OPTS=\"-b -B\"")); }
@Test public void testBashAcceptsNullCommand() throws Exception { File temp = File.createTempFile("abc", "b"); temp.deleteOnExit(); AutoComplete.bash("script", temp, null, new CommandLine(new TopLevel())); assertTrue(temp.length() > 0); }
@Test public void testBashRejectsNullOut() throws Exception { File commandFile = File.createTempFile("abc", "b"); commandFile.deleteOnExit(); try { AutoComplete.bash("script", null, commandFile, new CommandLine(new TopLevel())); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals(null, ok.getMessage()); } }
@Test public void testCompletionScript() throws IOException { String actual = AutoComplete.bash("rcmd", new CommandLine(new HyphenatedCommand())); String expected = format(AutoCompleteTest.loadTextFromClasspath("/hyphenated_completion.bash"), CommandLine.VERSION); assertEquals(expected, actual); } }
@Test public void testBashRejectsNullScript() { try { AutoComplete.bash(null, new CommandLine(new TopLevel())); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals("scriptName", ok.getMessage()); } }
@Test public void basic() throws Exception { String script = AutoComplete.bash("basicExample", new CommandLine(new BasicExample())); String expected = format(loadTextFromClasspath("/basic.bash"), CommandLine.VERSION, spaced(TimeUnit.values())); assertEquals(expected, script); }
@Test public void testBashify() { CommandSpec cmd = CommandSpec.create().addOption( OptionSpec.builder("-x") .type(String.class) .paramLabel("_A\tB C") .completionCandidates(Arrays.asList("1")).build()); String actual = AutoComplete.bash("bashify", new CommandLine(cmd)); String expected = format(loadTextFromClasspath("/bashify_completion.bash"), CommandLine.VERSION); assertEquals(expected, actual); }
@Test public void nestedSubcommands() throws Exception { CommandLine hierarchy = new CommandLine(new TopLevel()) .addSubcommand("sub1", new Sub1()) .addSubcommand("sub2", new CommandLine(new Sub2()) .addSubcommand("subsub1", new Sub2Child1()) .addSubcommand("subsub2", new Sub2Child2()) ); String script = AutoComplete.bash("picocompletion-demo", hierarchy); String expected = format(loadTextFromClasspath("/picocompletion-demo_completion.bash"), CommandLine.VERSION, spaced(TimeUnit.values())); assertEquals(expected, script); }
@Test public void testBooleanArgFilter() { @Command(name = "booltest") class App { @Option(names = "-b") boolean primitive; @Option(names = "-B") Boolean object; } String actual = AutoComplete.bash("booltest", new CommandLine(new App())); assertThat(actual, CoreMatchers.containsString("FLAG_OPTS=\"-b -B\"")); }
@Test public void testBashRejectsNullCommandLine() { try { AutoComplete.bash("script", null); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals("commandLine", ok.getMessage()); } }
@Test public void testBashAcceptsNullCommand() throws Exception { File temp = File.createTempFile("abc", "b"); temp.deleteOnExit(); AutoComplete.bash("script", temp, null, new CommandLine(new TopLevel())); assertTrue(temp.length() > 0); }
@Test public void testBashRejectsNullOut() throws Exception { File commandFile = File.createTempFile("abc", "b"); commandFile.deleteOnExit(); try { AutoComplete.bash("script", null, commandFile, new CommandLine(new TopLevel())); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals(null, ok.getMessage()); } }
@Test public void testCompletionScript() throws IOException { String actual = AutoComplete.bash("rcmd", new CommandLine(new HyphenatedCommand())); String expected = format(AutoCompleteTest.loadTextFromClasspath("/hyphenated_completion.bash"), CommandLine.VERSION); assertEquals(expected, actual); } }
@Test public void testBashRejectsNullScript() { try { AutoComplete.bash(null, new CommandLine(new TopLevel())); fail("Expected NPE"); } catch (NullPointerException ok) { assertEquals("scriptName", ok.getMessage()); } }
@Test public void basic() throws Exception { String script = AutoComplete.bash("basicExample", new CommandLine(new BasicExample())); String expected = format(loadTextFromClasspath("/basic.bash"), CommandLine.VERSION, spaced(TimeUnit.values())); assertEquals(expected, script); }
@Test public void testBashify() { CommandSpec cmd = CommandSpec.create().addOption( OptionSpec.builder("-x") .type(String.class) .paramLabel("_A\tB C") .completionCandidates(Arrays.asList("1")).build()); String actual = AutoComplete.bash("bashify", new CommandLine(cmd)); String expected = format(loadTextFromClasspath("/bashify_completion.bash"), CommandLine.VERSION); assertEquals(expected, actual); }