All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.jbang.cli.Completion Maven / Gradle / Ivy

There is a newer version: 0.121.0
Show newest version
package dev.jbang.cli;

import java.io.IOException;
import java.io.PrintStream;

import picocli.AutoComplete;
import picocli.CommandLine;

@CommandLine.Command(name = "completion", description = "Output auto-completion script for bash/zsh.\nUsage: source <(jbang completion)")
public class Completion extends BaseCommand {

	@Override
	public Integer doCall() throws IOException {
		return completion();
	}

	public int completion() throws IOException {
		String script = AutoComplete.bash(
				spec.parent().name(),
				spec.parent().commandLine());
		// not PrintWriter.println: scripts with Windows line separators fail in strange
		// ways!

		PrintStream out = System.out;
		out.print(script);
		out.print('\n');
		out.flush();
		return EXIT_OK;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy