Merge pull request #70 from resin-io/refactor/new-visuals

Upgrade Resin CLI Visuals and use it's new capabilities
This commit is contained in:
Juan Cruz Viotti 2015-06-12 09:47:30 -04:00
commit 381e63bfc9
7 changed files with 30 additions and 19 deletions

View File

@ -39,12 +39,7 @@
if (options.type != null) { if (options.type != null) {
return callback(null, options.type); return callback(null, options.type);
} }
return resin.models.device.getSupportedDeviceTypes(function(error, deviceTypes) { return visuals.patterns.selectDeviceType(callback);
if (error != null) {
return callback(error);
}
return visuals.widgets.select('Select a type', deviceTypes, callback);
});
}, function(type, callback) { }, function(type, callback) {
options.type = type; options.type = type;
return resin.models.application.create(params.name, options.type, callback); return resin.models.application.create(params.name, options.type, callback);
@ -162,7 +157,12 @@
function(callback) { function(callback) {
var currentDirectoryBasename; var currentDirectoryBasename;
currentDirectoryBasename = path.basename(currentDirectory); currentDirectoryBasename = path.basename(currentDirectory);
return visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback); return visuals.form.ask({
label: 'What is the name of your application?',
name: 'application',
type: 'text',
value: currentDirectoryBasename
}, callback);
}, function(applicationName, callback) { }, function(applicationName, callback) {
return exports.create.action({ return exports.create.action({
name: applicationName name: applicationName

View File

@ -32,7 +32,7 @@
if (error != null) { if (error != null) {
console.error("Unable to open a web browser in the current environment.\nPlease visit " + TOKEN_URL + " manually."); console.error("Unable to open a web browser in the current environment.\nPlease visit " + TOKEN_URL + " manually.");
} }
return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback); return visuals.patterns.loginWithToken(callback);
}); });
}, function(token, callback) { }, function(token, callback) {
return resin.auth.loginWithToken(token, callback); return resin.auth.loginWithToken(token, callback);
@ -97,7 +97,7 @@
if (hasOptionCredentials) { if (hasOptionCredentials) {
return callback(null, options); return callback(null, options);
} }
return visuals.widgets.register(callback); return visuals.patterns.register(callback);
}, function(credentials, callback) { }, function(credentials, callback) {
return resin.auth.register(credentials, function(error, token) { return resin.auth.register(credentials, function(error, token) {
return callback(error, credentials); return callback(error, credentials);

View File

@ -106,7 +106,11 @@
if (!_.isEmpty(params.newName)) { if (!_.isEmpty(params.newName)) {
return callback(null, params.newName); return callback(null, params.newName);
} }
return visuals.widgets.ask('How do you want to name this device?', null, callback); return visuals.form.ask({
label: 'How do you want to name this device?',
name: 'device',
type: 'text'
}, callback);
}, function(newName, callback) { }, function(newName, callback) {
return resin.models.device.rename(params.name, newName, callback); return resin.models.device.rename(params.name, newName, callback);
} }

View File

@ -44,10 +44,7 @@ exports.create =
return callback(new Error('You already have an application with that name!')) return callback(new Error('You already have an application with that name!'))
return callback(null, options.type) if options.type? return callback(null, options.type) if options.type?
visuals.patterns.selectDeviceType(callback)
resin.models.device.getSupportedDeviceTypes (error, deviceTypes) ->
return callback(error) if error?
visuals.widgets.select('Select a type', deviceTypes, callback)
(type, callback) -> (type, callback) ->
options.type = type options.type = type
@ -216,7 +213,12 @@ exports.init =
(callback) -> (callback) ->
currentDirectoryBasename = path.basename(currentDirectory) currentDirectoryBasename = path.basename(currentDirectory)
visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback) visuals.form.ask
label: 'What is the name of your application?'
name: 'application'
type: 'text'
value: currentDirectoryBasename
, callback
(applicationName, callback) -> (applicationName, callback) ->

View File

@ -44,7 +44,7 @@ exports.login =
Please visit #{TOKEN_URL} manually. Please visit #{TOKEN_URL} manually.
""" """
visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback) visuals.patterns.loginWithToken(callback)
(token, callback) -> (token, callback) ->
resin.auth.loginWithToken(token, callback) resin.auth.loginWithToken(token, callback)
@ -131,7 +131,7 @@ exports.signup =
(callback) -> (callback) ->
return callback(null, options) if hasOptionCredentials return callback(null, options) if hasOptionCredentials
visuals.widgets.register(callback) visuals.patterns.register(callback)
(credentials, callback) -> (credentials, callback) ->
resin.auth.register credentials, (error, token) -> resin.auth.register credentials, (error, token) ->

View File

@ -145,7 +145,12 @@ exports.rename =
(callback) -> (callback) ->
if not _.isEmpty(params.newName) if not _.isEmpty(params.newName)
return callback(null, params.newName) return callback(null, params.newName)
visuals.widgets.ask('How do you want to name this device?', null, callback)
visuals.form.ask
label: 'How do you want to name this device?'
name: 'device'
type: 'text'
, callback
(newName, callback) -> (newName, callback) ->
resin.models.device.rename(params.name, newName, callback) resin.models.device.rename(params.name, newName, callback)

View File

@ -59,7 +59,7 @@
"nplugm": "^2.2.0", "nplugm": "^2.2.0",
"npm": "^2.6.1", "npm": "^2.6.1",
"open": "0.0.5", "open": "0.0.5",
"resin-cli-visuals": "^0.1.1", "resin-cli-visuals": "^0.2.0",
"resin-config-inject": "^2.0.0", "resin-config-inject": "^2.0.0",
"resin-image": "^1.1.3", "resin-image": "^1.1.3",
"resin-image-manager": "^1.1.0", "resin-image-manager": "^1.1.0",