Skip to content

Commit

Permalink
Fix show-few option for ScanCommand (apache#3905)
Browse files Browse the repository at this point in the history
Fix `-f, --show-few` options for ScanCommand and subclasses

* Make GrepCommand (and EGrepCommand) respect the show-few option
* Suppress the show-few option from appearing in the DeleteManyCommand,
  which has its own `-f, --force` option

---------

Co-authored-by: Christopher Tubbs <[email protected]>
  • Loading branch information
rsingh433 and ctubbsii authored Nov 14, 2023
1 parent 0473629 commit db98f7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s
if (cl.getArgList().isEmpty()) {
throw new MissingArgumentException("No terms specified");
}
// Configure formatting options
final FormatterConfig config = new FormatterConfig();
config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
if (cl.hasOption(showFewOpt.getOpt())) {
final String showLength = cl.getOptionValue(showFewOpt.getOpt());
try {
final int length = Integer.parseInt(showLength);
config.setShownLength(length);
} catch (NumberFormatException nfe) {
Shell.log.error("Arg must be an integer.", nfe);
} catch (IllegalArgumentException iae) {
Shell.log.error("Arg must be greater than one.", iae);
}
}
final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
@SuppressWarnings("deprecation")
final org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter =
Expand Down Expand Up @@ -87,8 +101,6 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s
fetchColumns(cl, scanner, interpeter);

// output the records
final FormatterConfig config = new FormatterConfig();
config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
printRecords(cl, shellState, config, scanner, formatter, printFile);
} finally {
scanner.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@

public class ScanCommand extends Command {

private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, showFewOpt,
formatterOpt, interpreterOpt, formatterInterpeterOpt, outputFileOpt, scanOptCf, scanOptCq;
private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, formatterOpt,
interpreterOpt, formatterInterpeterOpt, outputFileOpt, scanOptCf, scanOptCq;

protected Option showFewOpt;
protected Option timestampOpt;
protected Option profileOpt;
private Option optStartRowExclusive;
Expand Down Expand Up @@ -110,8 +111,7 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s
if (cl.hasOption(contextOpt.getOpt())) {
classLoaderContext = cl.getOptionValue(contextOpt.getOpt());
}
// handle first argument, if present, the authorizations list to
// scan with
// handle first argument, if present, the authorizations list to scan with
final Authorizations auths = getAuths(cl, shellState);
final Scanner scanner = shellState.getAccumuloClient().createScanner(tableName, auths);
if (classLoaderContext != null) {
Expand Down Expand Up @@ -481,7 +481,6 @@ public Options getOptions() {
o.addOption(timestampOpt);
o.addOption(disablePaginationOpt);
o.addOption(OptUtil.tableOpt("table to be scanned"));
o.addOption(showFewOpt);
o.addOption(formatterOpt);
o.addOption(interpreterOpt);
o.addOption(formatterInterpeterOpt);
Expand All @@ -491,6 +490,7 @@ public Options getOptions() {
// supported subclasses must handle the output file option properly
// only add this option to commands which handle it correctly
o.addOption(outputFileOpt);
o.addOption(showFewOpt);
}
o.addOption(profileOpt);
o.addOption(sampleOpt);
Expand Down

0 comments on commit db98f7d

Please sign in to comment.