-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflutterjs.dart
More file actions
155 lines (144 loc) · 4.56 KB
/
flutterjs.dart
File metadata and controls
155 lines (144 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2025 The FlutterJS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:flutterjs_tools/command.dart';
/// ============================================================================
/// FlutterJS CLI Entry Point
/// ============================================================================
///
/// This file defines the main executable for the **FlutterJS** command-line
/// tool. It initializes argument parsing, handles global flags (`-v`, `-h`,
/// `doctor`, etc.), configures logging verbosity, and delegates execution to
/// `FlutterJSCommandRunner`.
///
/// This CLI is designed to be:
/// • Fully cross-platform (supports PowerShell/Windows help conventions)
/// • Verbose/debug-friendly (`-v`, `-vv`)
/// • Compatible with `args` command runner
/// • Extensible through the `FlutterJSCommandRunner` command registry
///
///
/// # Argument Behavior
///
/// ## Verbosity
/// `-v` or `--verbose`
/// Enables verbose logging
///
/// `-vv`
/// Enables **very** verbose logging (highest detail level)
///
///
/// ## Help Flags
/// Supports multiple help shortcuts:
/// • `-h`
/// • `--help`
/// • `help`
/// • PowerShell syntax: `-?`
/// • Windows syntax: `/?`
///
/// Help mode also automatically activates when:
/// • Only one argument is provided *and* it is a verbose flag
///
///
/// ## Doctor Mode
/// Triggered when:
/// • `doctor` is the first argument
/// • Or verbose + `doctor` as the last argument
///
/// Doctor mode prints diagnostic system information.
///
///
/// # Logging Control
///
/// `muteCommandLogging` is enabled when:
/// • Running help OR doctor
/// • AND verbosity is not super-verbose (`-vv`)
///
/// This keeps help/diagnostic output clean by hiding internal command logs.
///
///
/// # Execution Workflow
///
/// ```text
/// args → parse flags → configure verbosity & help → run FlutterJSCommandRunner
/// ↓
/// executes command
/// ```
///
/// Errors are handled gracefully:
/// • `UsageException` → prints usage information, exits with code 64
/// • Any other error → logs message, suggests running `-v` for debug
///
///
/// # Constants
///
/// `version` / `kVersion` → Current FlutterJS CLI version
/// `appName` / `kAppName` → Display name used by the CLI and commands
///
///
/// # Summary
///
/// This file contains the complete startup logic for the FlutterJS CLI,
/// including:
/// ✔ Flag normalization
/// ✔ Help/doctor routing
/// ✔ Verbose mode handling
/// ✔ Command runner instantiation
/// ✔ Error/exception management
///
/// The actual commands, subcommands, and handlers are registered inside
/// `FlutterJSCommandRunner`, making this entrypoint clean, simple, and easy to
/// extend.
///
const String version = '1.0.0';
const String appName = 'FlutterJS';
const String kVersion = '1.0.0';
const String kAppName = 'FlutterJS';
Future<void> main(List<String> args) async {
// Parse verbose flags early
final bool veryVerbose = args.contains('-vv');
final bool verbose =
args.contains('-v') || args.contains('--verbose') || veryVerbose;
// Support universal help idioms (PowerShell, Windows)
final int powershellHelpIndex = args.indexOf('-?');
if (powershellHelpIndex != -1) {
args[powershellHelpIndex] = '-h';
}
final int slashQuestionHelpIndex = args.indexOf('/?');
if (slashQuestionHelpIndex != -1) {
args[slashQuestionHelpIndex] = '-h';
}
final bool help =
args.contains('-h') ||
args.contains('--help') ||
(args.isNotEmpty && args.first == 'help') ||
(args.length == 1 && verbose);
final bool doctor =
(args.isNotEmpty && args.first == 'doctor') ||
(args.length == 2 && verbose && args.last == 'doctor');
final bool muteCommandLogging = (help || doctor) && !veryVerbose;
final bool verboseHelp = help && verbose;
// Create and run command runner
final runner = FlutterJSCommandRunner(
verbose: verbose,
verboseHelp: verboseHelp,
muteCommandLogging: muteCommandLogging,
);
try {
await runner.run(args);
} on UsageException catch (e) {
print('${e.message}\n');
print(e.usage);
exit(64); // Command line usage error
} catch (e) {
if (verbose) {
print('Error: $e');
} else {
print('Error: $e');
print('Run with -v for more details.');
}
exit(1);
}
}