diff --git a/packages/dart/sshnoports/bin/sshnp.dart b/packages/dart/sshnoports/bin/sshnp.dart index c015a9b2a..774e6b8ae 100644 --- a/packages/dart/sshnoports/bin/sshnp.dart +++ b/packages/dart/sshnoports/bin/sshnp.dart @@ -107,7 +107,7 @@ void main(List 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 { diff --git a/packages/dart/sshnoports/lib/src/extended_arg_parser.dart b/packages/dart/sshnoports/lib/src/extended_arg_parser.dart index dfb5e2c0c..c2ce148c7 100644 --- a/packages/dart/sshnoports/lib/src/extended_arg_parser.dart +++ b/packages/dart/sshnoports/lib/src/extended_arg_parser.dart @@ -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; } @@ -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(); @@ -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;