
com.github.dakusui.actionunit.actions.cmd.CommanderUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of actionunit Show documentation
Show all versions of actionunit Show documentation
A library to build 'action' structure for testing
package com.github.dakusui.actionunit.actions.cmd;
import com.github.dakusui.actionunit.utils.Checks;
import static java.util.Objects.requireNonNull;
public enum CommanderUtils {
;
public static String summarize(String commandLine, int length) {
Checks.requireArgument(l -> l > 3, length);
return requireNonNull(commandLine).length() < length ?
replaceNewLines(commandLine) :
replaceNewLines(commandLine).substring(0, length - 3) + "...";
}
public static String quoteWithSingleQuotesForShell(String s) {
return String.format("'%s'", escapeSingleQuotesForShell(s));
}
private static String replaceNewLines(String s) {
return s.replaceAll("\n", " ");
}
private static String escapeSingleQuotesForShell(String s) {
return requireNonNull(s).replaceAll("('+)", "'\"$1\"'");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy