Skip to content

Fix serve arg oops #31

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

Merged
merged 2 commits into from
Apr 9, 2018
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
4 changes: 2 additions & 2 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'build_runner_command_base.dart';
import 'command_base.dart';

/// Command to execute pub run build_runner build.
class BuildCommand extends BuildRunnerCommandBase {
class BuildCommand extends CommandBase {
BuildCommand() : super(releaseDefault: true);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const _verbose = 'verbose';

/// Extend to get a command with the arguments common to all build_runner
/// commands.
abstract class BuildRunnerCommandBase extends Command<int> {
abstract class CommandBase extends Command<int> {
final bool releaseDefault;

BuildRunnerCommandBase({@required this.releaseDefault}) {
CommandBase({@required this.releaseDefault}) {
// TODO(nshahan) Expose more common args passed to build_runner commands.
// build_runner might expose args for use in wrapping scripts like this one.
argParser
Expand All @@ -45,13 +45,8 @@ abstract class BuildRunnerCommandBase extends Command<int> {
help: 'Enables verbose logging.');
}

Future<int> runCore(String command) async {
await checkPubspecLock();

var buildRunnerScript = await _buildRunnerScript();

final arguments = [command];

List<String> getArgs() {
var arguments = <String>[];
if ((argResults[_release] as bool) ?? releaseDefault) {
arguments.add('--$_release');
}
Expand All @@ -64,6 +59,15 @@ abstract class BuildRunnerCommandBase extends Command<int> {
if (argResults[_verbose] as bool) {
arguments.add('--$_verbose');
}
return arguments;
}

Future<int> runCore(String command) async {
await checkPubspecLock();

var buildRunnerScript = await _buildRunnerScript();

final arguments = [command]..addAll(getArgs());

var exitCode = 0;

Expand Down
20 changes: 18 additions & 2 deletions webdev/lib/src/command/serve_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import 'dart:async';

import 'build_runner_command_base.dart';
import 'command_base.dart';

/// Command to execute pub run build_runner serve.
class ServeCommand extends BuildRunnerCommandBase {
class ServeCommand extends CommandBase {
@override
final name = 'serve';

Expand All @@ -30,6 +30,22 @@ class ServeCommand extends BuildRunnerCommandBase {
help: 'Enables logging for each request to the server.');
}

@override
List<String> getArgs() {
var arguments = super.getArgs();

var hostname = argResults['hostname'] as String;
if (hostname != null) {
arguments.addAll(['--hostname', hostname]);
}

if (argResults['log-requests'] == true) {
arguments.add('--log-requests');
}

return arguments;
}

@override
Future<int> run() => runCore('serve');
}