From ae3f0b429d205bd222e6cedc2157b2c7b3c7d8f8 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 2 Jun 2015 12:32:35 -0400 Subject: [PATCH] Ask for confirmacion on app associate command --- build/actions/app.js | 15 ++++++++++++++- doc/cli.markdown | 3 +++ lib/actions/app.coffee | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/build/actions/app.js b/build/actions/app.js index f32cb875..6f5a3552 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -110,13 +110,26 @@ exports.associate = { signature: 'app associate ', description: 'associate a resin project', - help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory', + help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory', + options: [commandOptions.yes], permission: 'user', action: function(params, options, done) { var currentDirectory; currentDirectory = process.cwd(); return async.waterfall([ function(callback) { + return resin.models.application.has(params.name, callback); + }, function(hasApp, callback) { + var message; + if (!hasApp) { + return callback(new Error("Invalid application: " + params.name)); + } + message = "Are you sure you want to associate " + currentDirectory + " with " + params.name + "?"; + return visuals.patterns.confirm(options.yes, message, callback); + }, function(confirmed, callback) { + if (!confirmed) { + return done(); + } return vcs.initialize(currentDirectory, callback); }, function(callback) { return resin.models.application.get(params.name, callback); diff --git a/doc/cli.markdown b/doc/cli.markdown index 07ec21ae..294db705 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -177,6 +177,9 @@ Use this command to associate a project directory with a resin application. This command adds a 'resin' git remote to the directory and runs git init if necessary. +Notice this command asks for confirmation interactively. +You can avoid this by passing the `--yes` boolean option. + Examples: $ resin app associate MyApp diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index 47e3baf3..9d6c9470 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -146,11 +146,15 @@ exports.associate = This command adds a 'resin' git remote to the directory and runs git init if necessary. + Notice this command asks for confirmation interactively. + You can avoid this by passing the `--yes` boolean option. + Examples: $ resin app associate MyApp $ resin app associate MyApp --project my/app/directory ''' + options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> currentDirectory = process.cwd() @@ -158,6 +162,17 @@ exports.associate = async.waterfall [ (callback) -> + resin.models.application.has(params.name, callback) + + (hasApp, callback) -> + if not hasApp + return callback(new Error("Invalid application: #{params.name}")) + + message = "Are you sure you want to associate #{currentDirectory} with #{params.name}?" + visuals.patterns.confirm(options.yes, message, callback) + + (confirmed, callback) -> + return done() if not confirmed vcs.initialize(currentDirectory, callback) (callback) ->