Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/dcm #592

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ inputs:
runs:
using: "composite"
steps:

- name: Setup Dart
uses: dart-lang/setup-dart@v1
with:
Expand All @@ -20,10 +19,3 @@ runs:
- name: Get dependencies
run: dart pub get
shell: bash

- run: dart format --output=none --set-exit-if-changed .
shell: bash

- name: Analyze
run: dart analyze --fatal-infos --fatal-warnings .
shell: bash
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ jobs:
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

# - name: Install DCM
# uses: CQLabs/setup-dcm@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}

# - name: Run DCM
# uses: CQLabs/dcm-action@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# folders: lib


- name: Tests
uses: ./.github/actions/test
if: matrix.os != 'ubuntu-latest'
Expand All @@ -56,4 +68,4 @@ jobs:
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
27 changes: 27 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@ analyzer:
unused_local_variable: error
dead_code: error
avoid_void_async: error
linter:
rules:
public_member_api_docs: false
prefer_relative_imports: true
dart_code_metrics:
extends:
- package:dart_code_metrics_presets/recommended.yaml
metrics-exclude:
- test/**
rules-exclude:
- "test/**"
rules:
member-ordering:
order:
- public-fields
- private-fields
- constructors
- static-methods
- private-methods
- private-getters
- private-setters
- public-getters
- public-setters
- public-methods
- overridden-public-methods
- overridden-public-getters
- build-method
12 changes: 3 additions & 9 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ import 'package:fvm/src/utils/context.dart';
import 'package:scope/scope.dart';

Future<void> main(List<String> args) async {
final scope = Scope()
..value(
contextKey,
FVMContext.create(),
);
final scope = Scope()..value(contextKey, FVMContext.create());

await _flushThenExit(
await scope.run(
() => FvmCommandRunner().run((args)),
),
await scope.run(() => FvmCommandRunner().run((args))),
);
}

Expand All @@ -28,5 +22,5 @@ Future<void> main(List<String> args) async {
/// after you've decided to exit.
Future<void> _flushThenExit(int status) {
return Future.wait<void>([stdout.close(), stderr.close()])
.then<void>((_) => exit(status));
.then((_) => exit(status));
}
6 changes: 1 addition & 5 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ final kAppDirHome = join(kUserHome, kPackageName);
/// Flutter Channels
const kFlutterChannels = ['master', 'stable', 'dev', 'beta'];

final kAppConfigFile = join(
_configHome,
kPackageName,
kFvmConfigFileName,
);
final kAppConfigFile = join(_configHome, kPackageName, kFvmConfigFileName);

String get _configHome {
if (Platform.isWindows) {
Expand Down
5 changes: 1 addition & 4 deletions lib/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class AppDetailedException extends AppException {
final String info;

/// Constructor
const AppDetailedException(
super.message,
this.info,
);
const AppDetailedException(super.message, this.info);

@override
String toString() => message;
Expand Down
5 changes: 2 additions & 3 deletions lib/src/commands/base_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import 'package:args/command_runner.dart';
abstract class BaseCommand extends Command<int> {
BaseCommand();

@override
String get invocation => 'fvm $name';

/// Checks if the command-line option named [name] was parsed.
bool wasParsed(String name) => argResults!.wasParsed(name);

Expand All @@ -24,4 +21,6 @@ abstract class BaseCommand extends Command<int> {

/// Gets the parsed command-line option named [name] as `List<String>`.
List<String?> stringsArg(String name) => argResults![name] as List<String>;
@override
String get invocation => 'fvm $name';
}
4 changes: 2 additions & 2 deletions lib/src/commands/dart_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import 'base_command.dart';

/// Proxies Dart Commands
class DartCommand extends BaseCommand {
DartCommand();

@override
final name = 'dart';
@override
final description = 'Proxies Dart Commands';
@override
final argParser = ArgParser.allowAnything();

DartCommand();

@override
Future<int> run() async {
final version = ProjectService.fromContext.findVersion();
Expand Down
82 changes: 37 additions & 45 deletions lib/src/commands/doctor_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,11 @@ class DoctorCommand extends BaseCommand {
final description = 'Shows information about environment, '
'and project configuration.';

/// Constructor
DoctorCommand();

final console = Console();

@override
Future<int> run() async {
final project = ProjectService.fromContext.findAncestor();
final flutterWhich = which('flutter');
final dartWhich = which('dart');

console.writeLine('FVM Doctor:');
console.writeLine('-' * console.windowWidth);

_printProject(project);
_printIdeLinks(project);
_printEnvironmentDetails(flutterWhich, dartWhich);

return ExitCode.success.code;
}
/// Constructor
DoctorCommand();

void printFVMDetails(FVMContext context) {}
void _printProject(Project project) {
logger.info('Project:');
final table = createTable(['Project', project.name]);
Expand All @@ -55,7 +38,7 @@ class DoctorCommand extends BaseCommand {
['Is Flutter Project', project.isFlutter ? 'Yes' : 'No'],
[
'Dart Tool Generator Version',
project.dartToolGeneratorVersion ?? 'Not available'
project.dartToolGeneratorVersion ?? 'Not available',
],
['Dart tool version', project.dartToolVersion ?? 'Not available'],
['.gitignore Present', project.gitignoreFile.existsSync() ? 'Yes' : 'No'],
Expand All @@ -64,14 +47,11 @@ class DoctorCommand extends BaseCommand {
['Config path', relative(project.configPath, from: project.path)],
[
'Local cache dir',
relative(project.localVersionsCachePath, from: project.path)
relative(project.localVersionsCachePath, from: project.path),
],
[
'Version symlink',
relative(
project.localVersionSymlinkPath,
from: project.path,
)
relative(project.localVersionSymlinkPath, from: project.path),
],
]);

Expand Down Expand Up @@ -105,12 +85,14 @@ class DoctorCommand extends BaseCommand {

table.insertRow(['dart.flutterSdkPath', sdkPath ?? 'None']);
table.insertRow(
['Matches pinned version:', sdkPath == relativeSymlinkPath]);
['Matches pinned version:', sdkPath == relativeSymlinkPath],
);
} on FormatException {
logger
..err('Error parsing Vscode settings.json on ${settingsFile.path}')
..err(
'Please use a tool like https://jsonformatter.curiousconcept.com to validate and fix it');
'Please use a tool like https://jsonformatter.curiousconcept.com to validate and fix it',
);
throw AppException(
'Could not get vscode settings, please check settings.json',
);
Expand Down Expand Up @@ -141,11 +123,12 @@ class DoctorCommand extends BaseCommand {
} else {
table.insertRow([
kIntelliJ,
'No local.properties file found in android directory'
'No local.properties file found in android directory',
]);
}

final dartSdkFile = File(join(project.path, '.idea', 'libraries', 'Dart_SDK.xml'));
final dartSdkFile =
File(join(project.path, '.idea', 'libraries', 'Dart_SDK.xml'));

if (dartSdkFile.existsSync()) {
final dartSdk = dartSdkFile.readAsStringSync();
Expand All @@ -157,42 +140,36 @@ class DoctorCommand extends BaseCommand {
if (containsSymLinkName) {
table.insertRow([
'SDK Path',
'SDK Path points to project directory. $kIntelliJ will dynamically switch SDK when using "fvm use"'
'SDK Path points to project directory. $kIntelliJ will dynamically switch SDK when using "fvm use"',
]);
}
else {
} else {
table.insertRow([
'SDK Path',
'SDK Path points to project directory, but does not use the flutter_sdk symlink. Using "fvm use" will break the project. Please consult documentation.'
'SDK Path points to project directory, but does not use the flutter_sdk symlink. Using "fvm use" will break the project. Please consult documentation.',
]);
}
} else {
table.insertRow([
'SDK Path',
'SDK Path does not point to the project directory. "fvm use" will not make $kIntelliJ switch Flutter version. Please consult documentation.'
'SDK Path does not point to the project directory. "fvm use" will not make $kIntelliJ switch Flutter version. Please consult documentation.',
]);
}
} else {
table.insertRow([
kIntelliJ,
'No .idea folder found'
'No .idea folder found',
]);
}

logger.write(table.toString());
}

void _printEnvironmentDetails(
String? flutterWhich,
String? dartWhich,
) {
void _printEnvironmentDetails(String? flutterWhich, String? dartWhich) {
logger
..spacer
..info('Environment:');

var table = createTable(
['Environment Variables', 'Value'],
);
var table = createTable(['Environment Variables', 'Value']);

table.insertRows([
['Flutter PATH', flutterWhich ?? 'Not found'],
Expand All @@ -210,9 +187,7 @@ class DoctorCommand extends BaseCommand {

logger.write(table.toString());

table = createTable(
['Platform', 'Value'],
);
table = createTable(['Platform', 'Value']);

table.insertRows([
['OS', '${Platform.operatingSystem} ${Platform.operatingSystemVersion}'],
Expand All @@ -222,4 +197,21 @@ class DoctorCommand extends BaseCommand {

logger.write(table.toString());
}

void printFVMDetails() {}
@override
Future<int> run() async {
final project = ProjectService.fromContext.findAncestor();
final flutterWhich = which('flutter');
final dartWhich = which('dart');

console.writeLine('FVM Doctor:');
console.writeLine('-' * console.windowWidth);

_printProject(project);
_printIdeLinks(project);
_printEnvironmentDetails(flutterWhich, dartWhich);

return ExitCode.success.code;
}
}
11 changes: 2 additions & 9 deletions lib/src/commands/exec_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class ExecCommand extends BaseCommand {
final version = ProjectService.fromContext.findVersion();

if (argResults!.rest.isEmpty) {
throw UsageException(
'No command was provided to be executed',
usage,
);
throw UsageException('No command was provided to be executed', usage);
}

final cmd = argResults!.rest[0];
Expand All @@ -48,11 +45,7 @@ class ExecCommand extends BaseCommand {
}

// Runs exec command with pinned version
final results = await execCmd(
cmd,
execArgs,
cacheVersion,
);
final results = await execCmd(cmd, execArgs, cacheVersion);

return results.exitCode;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/commands/global_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class GlobalCommand extends BaseCommand {
/// Constructor
GlobalCommand();

@override
String get invocation => 'fvm global {version}';

@override
Future<int> run() async {
String? version;
Expand Down Expand Up @@ -102,4 +99,7 @@ class GlobalCommand extends BaseCommand {
}
return ExitCode.success.code;
}

@override
String get invocation => 'fvm global {version}';
}
Loading