<commit_before>_ = require('lodash-contrib')
async = require('async')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
commandOptions = require('./command-options')

exports.create =
	signature: 'app create <name>'
	description: 'create an application'
	help: '''
		Use this command to create a new resin.io application.

		You can specify the application type with the `--type` option.
		Otherwise, an interactive dropdown will be shown for you to select from.

		You can see a list of supported device types with
			$ resin devices supported

		Examples:
			$ resin app create MyApp
			$ resin app create MyApp --type raspberry-pi
	'''
	options: [
		{
			signature: 'type'
			parameter: 'type'
			description: 'application type'
			alias: 't'
		}
	]
	permission: 'user'
	action: (params, options, done) ->
		async.waterfall([

			(callback) ->
				return callback(null, options.type) if options.type?
				visuals.patterns.selectDeviceType(callback)

			(type, callback) ->
				resin.models.application.create(params.name, type, callback)

		], done)

exports.list =
	signature: 'apps'
	description: 'list all applications'
	help: '''
		Use this command to list all your applications.

		Notice this command only shows the most important bits of information for each app.
		If you want detailed information, use resin app <id> instead.

		Examples:
			$ resin apps
	'''
	permission: 'user'
	action: (params, options, done) ->
		resin.models.application.getAll (error, applications) ->
			return done(error) if error?
			console.log visuals.widgets.table.horizontal applications, [
				'id'
				'app_name'
				'device_type'<commit_msg>Use visuals.widgets.select for app create command<commit_after>_ = require('lodash-contrib')
async = require('async')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
commandOptions = require('./command-options')

exports.create =
	signature: 'app create <name>'
	description: 'create an application'
	help: '''
		Use this command to create a new resin.io application.

		You can specify the application type with the `--type` option.
		Otherwise, an interactive dropdown will be shown for you to select from.

		You can see a list of supported device types with
			$ resin devices supported

		Examples:
			$ resin app create MyApp
			$ resin app create MyApp --type raspberry-pi
	'''
	options: [
		{
			signature: 'type'
			parameter: 'type'
			description: 'application type'
			alias: 't'
		}
	]
	permission: 'user'
	action: (params, options, done) ->
		async.waterfall([

			(callback) ->
				return callback(null, options.type) if options.type?

				resin.models.device.getSupportedDeviceTypes (error, deviceTypes) ->
					return callback(error) if error?
					visuals.widgets.select('Select a type', deviceTypes, callback)

			(type, callback) ->
				resin.models.application.create(params.name, type, callback)

		], done)

exports.list =
	signature: 'apps'
	description: 'list all applications'
	help: '''
		Use this command to list all your applications.

		Notice this command only shows the most important bits of information for each app.
		If you want detailed information, use resin app <id> instead.

		Examples:
			$ resin apps
	'''
	permission: 'user'
	action: (params, options, done) ->
		resin.models.application.getAll (error, applications) ->
			return done(error) if error?
			console.log visuals.widgets.table.horizontal applications, [
				'id'
				'app_name'
				'device_type'
{'fraction_non_alphanumeric': 0.11079136690647481, 'fraction_numerical': 0.0, 'mean_word_length': 3.781292984869326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3062563', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1012, 'n_words': 349}