Skip to content

Commit

Permalink
fix(ui): 🎨 fixup start & enable flag logic
Browse files Browse the repository at this point in the history
refs #313

- the `ghost setup --start` flag
  - The default value for "start" is "prompt"
  - The fallback default value for "start", if it's not allowed to prompt is true
  - Passing --no-start will set start to false, and not prompt
  - Passing --start will set start to true, and not prompt

- the `ghost start --enable` flag
  - Enabling doesn't trigger any prompt
  - The default value for "enable" is true
  - Passing --enable doesn't change anything
  - Passing --no-enable prevents enabling

- calling `ghost uninstall` will now call `ghost stop --disable`
  • Loading branch information
ErisDS authored and acburdine committed Jul 10, 2017
1 parent 1b7bf97 commit d0ff7fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
15 changes: 11 additions & 4 deletions lib/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ class SetupCommand extends Command {
}

return this.ui.listr(tasks, {setup: true}).then(() => {
if (!argv.prompt || argv.start) {
// If we are not allowed to prompt, set the default value, which should be true
if (!argv.prompt) {
argv.start = true;
}

// If argv.start has a value, this means either --start or --no-start were explicitly provided
// (or --no-prompt was provided, and we already defaulted to true)
// In this case, we don't prompt, we use the value of argv.start
if (argv.start || argv.start === false) {
return Promise.resolve({yes: argv.start});
}

Expand All @@ -163,9 +171,8 @@ SetupCommand.description = 'Setup an installation of Ghost (after it is installe
SetupCommand.params = '[stages..]';
SetupCommand.options = {
start: {
description: 'Automatically start Ghost without prompting',
type: 'boolean',
default: false
description: '[--no-start] Enable/disable automatically starting Ghost',
type: 'boolean'
},
local: {
alias: 'l',
Expand Down
21 changes: 7 additions & 14 deletions lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,18 @@ class StartCommand extends Command {
instance.running = this.system.environment;
});

// @TODO --quiet will make enable never happen!
if (argv.quiet) {
return start();
}

return this.ui.run(start, 'Starting Ghost').then(() => {
// If process manager doesn't support enable behavior OR
// it's already enabled, then skip prompt
// If process manager doesn't support enable behavior OR it's already enabled, don't try to enable
if (!ProcessManager.supportsEnableBehavior(processInstance) || processInstance.isEnabled()) {
return Promise.resolve({yes: false});
argv.enable = false;
}

// If prompts are disabled or enable is passed,
// skip prompt
if (argv.enable || !argv.prompt) {
return Promise.resolve({yes: argv.enable});
}

return this.ui.confirm('Do you wish to enable the Ghost instance to start on reboot?')
}).then((answer) => {
if (!answer.yes) {
if (!argv.enable) {
return Promise.resolve();
}

Expand All @@ -74,8 +66,9 @@ class StartCommand extends Command {
StartCommand.description = 'Start an instance of Ghost';
StartCommand.options = {
enable: {
description: 'Enable the instance to restart on server reboot (if the process manager supports it)',
type: 'boolean'
description: '[--no-enable] Enable/don\'t enable the instance to restart on server reboot (if the process manager supports it)',
type: 'boolean',
default: true
}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/commands/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class UninstallCommand extends Command {
skip: () => !instance.running,
task: () => {
instance.loadRunningEnvironment(true);
// If the instance is currently running we need to make
// sure it gets stopped
return this.runCommand(StopCommand, {quiet: true});
// If the instance is currently running we need to make sure
// it gets stopped and disabled if possible
return this.runCommand(StopCommand, {disable: true});
}
}, {
title: 'Removing related configuration',
Expand Down

0 comments on commit d0ff7fe

Please sign in to comment.