Skip to content

Commit

Permalink
Merge pull request #707 from atsign-foundation/fix-x-flag
Browse files Browse the repository at this point in the history
fix: x flag
  • Loading branch information
gkc authored Jan 22, 2024
2 parents d0bd764 + 1aec3a8 commit 0675e02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/dart/sshnoports/bin/sshnp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void main(List<String> args) async {

await shell.done;
exit(0);
} else if (argResults.wasParsed(xFlag) && argResults[xFlag] as bool) {
} else if (argResults[outputExecutionCommandFlag] as bool) {
stdout.write('$res\n');
exit(0);
} else {
Expand Down
21 changes: 15 additions & 6 deletions packages/dart/sshnoports/lib/src/extended_arg_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@ class DefaultExtendedArgs {
static const outputExecutionCommand = false;
}

const xFlag = 'output-execution-command';
const sshClientOption = 'ssh-client';
const legacyDaemonFlag = 'legacy-daemon';
const outputExecutionCommandFlag = 'output-execution-command';

class ExtendedArgParser {
static ArgParser createArgParser() {
final parser = SshnpArg.createArgParser(parserType: ParserType.commandLine);

parser.addOption(
'ssh-client',
sshClientOption,
help: 'What to use for outbound ssh connections',
allowed: SupportedSshClient.values.map((e) => e.toString()),
defaultsTo: DefaultExtendedArgs.sshClient.toString(),
);

parser.addFlag(
'legacy-daemon',
legacyDaemonFlag,
help: 'Request is to a legacy (< 4.0.0) noports daemon',
defaultsTo: DefaultExtendedArgs.legacyDaemon,
negatable: false,
);

parser.addFlag(
xFlag,
outputExecutionCommandFlag,
abbr: 'x',
help: 'Output the command that would be executed, and exit',
defaultsTo: DefaultExtendedArgs.outputExecutionCommand,
negatable: false,
);

return parser;
}

Expand All @@ -59,7 +62,7 @@ class ExtendedArgParser {

if (results!.wasParsed('ssh-client')) {
final indices = coreArgs.indexed
.where((element) => element.$2 == '--ssh-client')
.where((element) => element.$2 == '--$sshClientOption')
.map((e) => e.$1)
.toList();

Expand All @@ -76,7 +79,13 @@ class ExtendedArgParser {
}

if (results!.wasParsed('legacy-daemon')) {
coreArgs.removeWhere((element) => element == '--legacy-daemon');
coreArgs.removeWhere((element) => element == '--$legacyDaemonFlag');
}

if (results!.wasParsed(outputExecutionCommandFlag)) {
coreArgs
.removeWhere((element) => element == '--$outputExecutionCommandFlag');
coreArgs.removeWhere((element) => element == '-x');
}

return coreArgs;
Expand Down

0 comments on commit 0675e02

Please sign in to comment.