/** wraps plain text in double quotes escaped for use in bash double-quoting */ public static String wrapBash(String value) { StringBuilder out = new StringBuilder(); try { wrapBash(value, out); } catch (IOException e) { //shouldn't happen for string buffer throw Throwables.propagate(e); } return out.toString(); }
cmd.add("bash -c "+BashStringEscapes.wrapBash(command));
@Nullable protected String knifeConfigFileOption() { if (knifeConfigFile!=null) return "-c "+knifeConfigFile; String knifeConfigFileFromConfig = entityConfig(ChefConfig.KNIFE_CONFIG_FILE); if (knifeConfigFileFromConfig!=null) return "-c "+BashStringEscapes.wrapBash(knifeConfigFileFromConfig); // if not supplied will use global config return null; }
result.add(wrapBash(hostAndPort.getHostText())); Integer whichPort = knifeWhichPort(hostAndPort); if (whichPort!=null) result.add("-p "+whichPort); result.add("-x "+wrapBash(checkNotNull(machine.getUser(), "user"))); result.add("-r "+wrapBash(runList.apply(entity()))); result.add("-j "+wrapBash(new GsonBuilder().create() .toJson(knifeAttributes)));
public static String warn(String message) { return "( echo "+BashStringEscapes.wrapBash(message)+" | tee /dev/stderr )"; }
/** fails with nice error if the given file does not exist */ public static String requireExecutable(String command) { return require("which "+BashStringEscapes.wrapBash(command), "The required executable \""+command+"\" does not exist"); }
/** fails with nice error if the given file does not exist */ public static String requireFile(String file) { return requireTest("-f "+BashStringEscapes.wrapBash(file), "The required file \""+file+"\" does not exist"); }
protected String knifeExecutable() { if (knifeExecutable!=null) return knifeExecutable; String knifeExecFromConfig = entityConfig(ChefConfig.KNIFE_EXECUTABLE); if (knifeExecFromConfig!=null) return BashStringEscapes.wrapBash(knifeExecFromConfig); // assume on the path, if executable not set return "knife"; }