caught exception when parsing arguments.

This commit is contained in:
vishalxl
2022-08-14 00:48:19 +05:30
parent 53303b075d
commit 61d8faab38
2 changed files with 48 additions and 34 deletions

View File

@ -6,6 +6,10 @@ import 'package:args/args.dart';
import 'package:crypto/crypto.dart';
import 'dart:convert'; // for the utf8.encode method
// name of executable
String exename = "nostr_console";
String version = "0.0.1";
// well known disposable test private key
const String testPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
const String testPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180";
@ -24,7 +28,9 @@ const String helpArg = "help";
int numLastDays = 1;
void printUsage() {
String usage = """usage: dartcl [OPTIONS]
String usage = """$exename version $version
usage: $exename [OPTIONS]
OPTIONS
@ -150,9 +156,10 @@ Future<void> main(List<String> arguments) async {
..addOption(prikeyArg, abbr:"p")
..addOption(lastdaysArg, abbr:"d")
..addOption(relayArg, abbr:"r")
..addFlag(helpArg, abbr:"h", defaultsTo: false);
ArgResults argResults = parser.parse(arguments);
..addFlag(helpArg, abbr:"h", defaultsTo: false)..allowsAnything;
try {
ArgResults argResults = parser.parse(arguments);
if( argResults[helpArg]) {
printUsage();
return;
@ -185,6 +192,13 @@ Future<void> main(List<String> arguments) async {
});
return;
}
} on FormatException catch (e) {
print(e.message);
return;
} on Exception catch (e) {
print(e);
return;
}
// the default in case no arguments are given is:
// get a user's events, then from its type 3 event, gets events of its follows,

View File

@ -1,6 +1,6 @@
name: nostr_console
description: A sample command-line application.
version: 1.0.0
version: 0.0.1
# homepage: https://www.example.com
environment: