-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nstack command line tool package
- Loading branch information
maru
committed
Apr 28, 2020
1 parent
b88220b
commit 9acccc3
Showing
3 changed files
with
140 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,6 @@ build/ | |
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
/// Handles all the commands | ||
void main(List<String> 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<String> 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<String> 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'; |