use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Main method _keys.
@Description("Show the jpm machine keys")
public void _keys(KeysOptions opts) throws Exception {
boolean any = opts.pem() || opts.extended() || opts.hex();
if (opts.extended()) {
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(settings.getPrivateKey());
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(settings.getPublicKey());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
privateKey.getAlgorithm();
if (opts.secret())
out.format("private %s", privateKey);
out.format("public %s", publicKey);
}
if (opts.hex()) {
if (opts.secret())
out.format("private %s", Hex.toHexString(settings.getPrivateKey()));
out.format("public %s", Hex.toHexString(settings.getPublicKey()));
}
if (opts.pem() || !any) {
formatKey(settings.getPublicKey(), "PUBLIC");
if (opts.secret())
formatKey(settings.getPrivateKey(), "PRIVATE");
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Main method _platform.
/**
* Show the platform info.
*
* @param opts
* @throws IOException
* @throws Exception
*/
@Description("Show platform information")
public void _platform(PlatformOptions opts) throws IOException, Exception {
CommandLine cli = opts._command();
List<String> cmds = opts._arguments();
if (cmds.isEmpty()) {
if (opts.verbose()) {
Justif j = new Justif(80, 30, 40, 50, 60);
jpm.getPlatform().report(j.formatter());
out.append(j.wrap());
} else
out.println(jpm.getPlatform().getName());
} else {
String execute = cli.execute(jpm.getPlatform(), cmds.remove(0), cmds);
if (execute != null) {
out.append(execute);
}
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Main method _command.
@Description("Manage the jpm4j commands")
public void _command(CommandOptions opts) throws Exception {
if (opts.remove()) {
Instructions instrs = new Instructions(opts._arguments());
for (CommandData cmd : jpm.getCommands()) {
if (instrs.matches(cmd.name)) {
jpm.deleteCommand(cmd.name);
}
}
return;
}
if (opts._arguments().isEmpty()) {
print(jpm.getCommands());
return;
}
String cmd = opts._arguments().get(0);
CommandData data = jpm.getCommand(cmd);
if (data == null) {
error("Not found: %s", cmd);
} else {
CommandData newer = new CommandData();
JustAnotherPackageManager.xcopy(data, newer);
if (updateCommandData(newer, opts)) {
jpm.deleteCommand(data.name);
String result = jpm.createCommand(newer, true);
if (result != null)
error("Failed to update command %s: %s", cmd, result);
}
print(newer);
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Windows method _path.
@Description("Add the bin directory for this jpm to your PATH in the user's environment variables")
public void _path(PathOptions options) {
RegistryKey env = RegistryKey.HKEY_CURRENT_USER.getSubKey("Environment");
if (env == null) {
reporter.error("Cannot find key for environment HKEY_CURRENT_USER/Environment");
return;
}
String path = env.getString("Path");
String[] parts = path == null ? new String[0] : path.split(File.pathSeparator);
List<String> paths = new ArrayList<String>(Arrays.asList(parts));
boolean save = false;
if (options.extra() != null) {
paths.addAll(options.extra());
save = true;
}
for (int i = 0; i < parts.length; i++) {
System.out.printf("%2d:%s %s %s%n", i, parts[i].toLowerCase().contains("jpm") ? "*" : " ", new File(parts[i]).isDirectory() ? " " : "!", parts[i]);
}
if (options.remove()) {
if (!paths.remove(jpm.getBinDir().getAbsolutePath())) {
reporter.error("Could not find %s", jpm.getBinDir());
}
save = true;
}
if (options.delete() != null) {
Instructions instr = new Instructions(options.delete());
paths = new ArrayList<String>(instr.select(paths, true));
}
if (options.add()) {
paths.remove(jpm.getBinDir().getAbsolutePath());
paths.add(jpm.getBinDir().getAbsolutePath());
save = true;
}
if (save) {
String p = Strings.join(File.pathSeparator, paths);
env.setString("Path", p);
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Unix method _path.
@Description("Add the bin directory for this jpm to your PATH in the user's environment variables")
public void _path(PathOptions options) throws IOException {
File file = options.profile() == null ? IO.getFile("~/.profile") : IO.getFile(IO.home, options.profile());
if (!file.isFile()) {
if (!options.force()) {
reporter.error("No such file %s", file);
return;
}
IO.store("# created by jpm\n", file);
}
String[] parts = System.getenv("PATH").split(":");
List<String> paths = new ArrayList<String>(Arrays.asList(parts));
for (int i = 0; i < parts.length; i++) {
System.out.printf("%2d:%s %s %s%n", i, parts[i].toLowerCase().contains("jpm") ? "*" : " ", new File(parts[i]).isDirectory() ? " " : "!", parts[i]);
}
String bd = jpm.getBinDir().getAbsolutePath();
String s = IO.collect(file);
//
if (options.remove() || options.add()) {
if (!bd.equals(getGlobalBinDir().getAbsolutePath())) {
s = s.replaceAll("(PATH\\s*=)" + bd + ":(.*\\$PATH)", "$1$2");
logger.debug("removed {}", bd);
}
}
if (options.delete() != null) {
for (String delete : options.delete()) {
s = s.replaceAll("(PATH\\s*=)" + Glob.toPattern(delete) + ":(.*\\$PATH)", "$1$2");
}
}
//
// Remove any orphans
//
s = s.replaceAll("\\s*(set|export)\\s+PATH\\s*=\\$PATH\\s*", "");
List<String> additions = new ArrayList<String>();
if (options.add()) {
if (!bd.equals(getGlobalBinDir().getAbsolutePath())) {
additions.add(bd);
}
}
if (options.extra() != null)
for (String add : options.extra()) {
File f = IO.getFile(add);
if (!f.isDirectory()) {
reporter.error("%s is not a directory, not added", f.getAbsolutePath());
} else {
if (!paths.contains(f.getAbsolutePath()))
additions.add(f.getAbsolutePath());
}
}
if (!additions.isEmpty()) {
s += "\nexport PATH=" + Strings.join(":", additions) + ":$PATH\n";
logger.debug("s {}", s);
}
IO.store(s, file);
}
Aggregations