Skip to content

Commit

Permalink
app command now shows version and description
Browse files Browse the repository at this point in the history
  • Loading branch information
codetricity committed Feb 12, 2021
1 parent de8d258 commit fb10838
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// "firmwareVersion": "01.51",
/// ...
import 'dart:io';
import 'package:apitest/cli/app_cli.dart';
import 'package:args/args.dart';
import 'package:yaml/yaml.dart';
import 'package:apitest/cli/auto_bracket_cli.dart';
Expand Down Expand Up @@ -85,7 +86,8 @@ void main(List<String> args) async {
..addCommand(SetMySettingCli())
..addCommand(ShutterVolumeCli())
..addCommand(DownloadCli())
..addCommand(StopCaptureCli());
..addCommand(StopCaptureCli())
..addCommand(AppCli());

await runner.run(args).catchError((error) {
if (error is! UsageException) throw error;
Expand Down
32 changes: 32 additions & 0 deletions lib/cli/00_pubspec_contents.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var pubspecContents = '''
name: apitest
version: 0.1.1-alpha
description: >-
RICOH THETA WebAPI test implementation with Dart by Oppkey and the community.
Based on RICOH THETA API v2.1
Direct questions to the community.theta360.guide.
The WebAPI is usually used with mobile apps. This tool is a command line
interface to a Dart library that can also be used with Flutter for iOS
and Android. This command line tool can be put into bash scripts.
dependencies:
http: ^0.12.2
args: ^1.6.0
theta:
git:
url: https://github.com/codetricity/theta
ref: main
# change the path below to the path above for production use
# path: ../theta
dcli: ^0.41.0
yaml: ^2.2.1
path: ^1.7.0
environment:
sdk: '>=2.10.0 <3.0.0'
dev_dependencies:
pedantic: ^1.0.0
repository: https://github.com/theta360developers/webapi
homepage: https://theta360developers.github.io/webapi/
''';
10 changes: 4 additions & 6 deletions lib/cli/app_cli.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:args/command_runner.dart';
import 'dart:io';
import 'package:yaml/yaml.dart';
import 'package:path/path.dart' as p;
import '00_pubspec_contents.dart';

class AppCli extends Command {
@override
Expand All @@ -21,17 +21,15 @@ class AppCli extends Command {

@override
void run() async {
var pathToYaml =
p.join(p.dirname(Platform.script.toFilePath()), '../pubspec.yaml');
var file = await File(pathToYaml);
var yamlString = file.readAsStringSync();
var conf = loadYaml(yamlString);
var conf = loadYaml(pubspecContents);
if (argResults.arguments.isEmpty) {
printUsage();
} else if (argResults.wasParsed('version')) {
print(conf['version']);
} else if (argResults.wasParsed('description')) {
print('\n');
print(conf['description']);
print('\n');
} else if (argResults.wasParsed('repository')) {
print(conf['repository']);
} else if (argResults.wasParsed('homepage')) {
Expand Down
48 changes: 48 additions & 0 deletions lib/cli/app_does_not_work_cli.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:args/command_runner.dart';
import 'dart:io';
import 'package:yaml/yaml.dart';
import 'package:path/path.dart' as p;

// this does not work as the pubspec.yaml file is not distributed
// with the theta.exe binary

class AppCli extends Command {
@override
final name = 'app';

@override
final description = 'information on this app. --version shows version';

AppCli() {
argParser
..addFlag('version',
help: 'version information for this app', negatable: false)
..addFlag('description', help: 'app description', negatable: false)
..addFlag('repository', help: 'url of GitHub repo', negatable: false)
..addFlag('homepage', help: 'blog for this tool', negatable: false);
}

@override
void run() async {
var pathToYaml =
p.join(p.dirname(Platform.script.toFilePath()), '../pubspec.yaml');
var file = await File(pathToYaml);
var yamlString = file.readAsStringSync();
var conf = loadYaml(yamlString);
if (argResults.arguments.isEmpty) {
printUsage();
} else if (argResults.wasParsed('version')) {
print(conf['version']);
} else if (argResults.wasParsed('description')) {
print(conf['description']);
} else if (argResults.wasParsed('repository')) {
print(conf['repository']);
} else if (argResults.wasParsed('homepage')) {
print(conf['homepage']);
} else {
printUsage();
}

exit(0);
}
}
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: apitest
# IMPORTANT: copy the contents of this file into ./lib/cli/00_pubspec_contents.dart
# when the version or description is changed.
version: 0.1.1-alpha
# IMPORTANT: copy the contents of this file into ./lib/cli/00_pubspec_contents.dart
# when the version or description is changed.
description: >-
RICOH THETA WebAPI test implementation with Dart by Oppkey and the community.
Based on RICOH THETA API v2.1
Expand Down
Binary file modified script_examples/theta.exe
Binary file not shown.

0 comments on commit fb10838

Please sign in to comment.