diff --git a/.gitignore b/.gitignore index aa20bf3..d4172dd 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,6 @@ build/ *.class # Generated files -bin/ gen/ out/ diff --git a/nstack_tooling/.gitignore b/nstack_tooling/.gitignore index bb431f0..06bc65e 100644 --- a/nstack_tooling/.gitignore +++ b/nstack_tooling/.gitignore @@ -1,75 +1,15 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ +# Files and directories created by pub .dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies .packages -.pub-cache/ -.pub/ +# Remove the following pattern if you wish to check in your lock file +pubspec.lock + +# Conventional directory for build outputs build/ -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java +# Directory created by dartdoc +doc/api/ -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Flutter.podspec -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* +.idea/ -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +assets \ No newline at end of file diff --git a/nstack_tooling/bin/main.dart b/nstack_tooling/bin/main.dart new file mode 100644 index 0000000..0f91c8c --- /dev/null +++ b/nstack_tooling/bin/main.dart @@ -0,0 +1,131 @@ +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:logging/logging.dart'; + +/// Handles all the commands +void main(List arguments) { + Logger.root.level = Level.INFO; // defaults to Level.INFO + recordStackTraceAtLevel = Level.ALL; + Logger.root.onRecord.listen((record) { + if (record.level == Level.SEVERE) { + stderr.writeln('[${record.level.name}] ${record.message}'); + } else { + stdout.writeln('[${record.level.name}] ${record.message}'); + } + }); + exitCode = 0; + + final argResults = parseArguments(arguments); + if (argResults == null) return; + + if (argResults.command == null) { + processArgs(argResults.arguments); + } else { + switch (argResults.command.name) { + case 'build': + // TODO: processBuildCommand(argResults.command); + break; + case 'create': + //TODO: processCreateCommand(argResults.command); + break; + default: + exit_with(ERROR_COMMAND_NOT_FOUND); + } + } +} + +/// Parses command-line arguments and returns results +ArgResults parseArguments(List arguments) { + final createParser = ArgParser() + ..addFlag('json', + help: 'generates json type of config file', + negatable: false, + abbr: 'j'); + + final buildParser = ArgParser() + ..addFlag('watch', + abbr: 'w', + negatable: false, + help: 'Watches for any file changes and re-generates dart code') + ..addFlag('smart-watch', + negatable: false, + help: + 'Smartly watches for file changes that matters and re-generates dart code') + ..addFlag('verbose', + abbr: 'v', negatable: false, help: 'prints verbose logs'); + + final parser = ArgParser() + ..addCommand('create', createParser) + ..addCommand('build', buildParser) + ..addFlag('help', + abbr: 'h', help: 'prints usage information', negatable: false) + ..addFlag('version', abbr: 'v', help: 'prints current version') + ..addFlag('info', abbr: 'i', help: 'print library info', negatable: false) + ..addFlag('check-updates', + abbr: 'u', help: 'Check for update', negatable: false); + try { + var result = parser.parse(arguments); + return result; + } on Error catch (e) { + exit_with( + 'Invalid command input. see spider --help for info.', e.stackTrace); + return null; + } +} + +/// Called when no command is passed for spider +/// Process available options for spider executable +void processArgs(List arguments) { + if (arguments.contains('--help')) { + printHelp(); + } else if (arguments.contains('--version')) { + printVersion(); + } else if (arguments.contains('--info')) { + printInfo(); + } else { + printHelp(); + } +} + +/// exits process with a message on command-line +void exit_with(String msg, [StackTrace stackTrace]) { + error(msg, stackTrace); + exitCode = 2; + exit(2); +} + +/// logs an error +void error(String msg, [StackTrace stackTrace]) => + Logger('Spider').log(Level('ERROR', 1100), msg, null, stackTrace); + +/// prints library help +void printHelp() => stdout.writeln(HELP); + +/// prints library info +void printInfo() => stdout.writeln(INFO); + +/// prints library version +void printVersion() => stdout.writeln(VERSION); + +/// constants +const String VERSION = '1.0.0'; + +const String HELP = ''' +NSTACK: + Some great help. +'''; + +const String INFO = ''' +NSTACK: + A small dart command-line tool for generating NStack assets. + + VERSION $VERSION + AUTHOR Nodes + HOMEPAGE https://nstack.io + SDK VERSION 2.6 + + see nstacktooling --help for more available commands. +'''; + +const String ERROR_COMMAND_NOT_FOUND = 'No command found. Use NStack --help to see available commands';