diff --git a/build/actions/index.js b/build/actions/index.js index 57ad1a3f..db9efe23 100644 --- a/build/actions/index.js +++ b/build/actions/index.js @@ -29,7 +29,8 @@ limitations under the License. help: require('./help'), os: require('./os'), settings: require('./settings'), - config: require('./config') + config: require('./config'), + sync: require('./sync') }; }).call(this); diff --git a/build/actions/sync.js b/build/actions/sync.js new file mode 100644 index 00000000..41350628 --- /dev/null +++ b/build/actions/sync.js @@ -0,0 +1,68 @@ + +/* +Copyright 2016 Resin.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +(function() { + module.exports = { + signature: 'sync ', + description: '(beta) sync your changes with a device', + help: 'Use this command to sync your local changes to a certain device on the fly.\n\nYou can save all the options mentioned below in a `resin-sync.yml` file,\nby using the same option names as keys. For example:\n\n $ cat $PWD/resin-sync.yml\n source: src/\n before: \'echo Hello\'\n exec: \'python main.py\'\n ignore:\n - .git\n - node_modules/\n progress: true\n\nNotice that explicitly passed command options override the ones set in the configuration file.\n\nExamples:\n\n $ resin sync 7cf02a6\n $ resin sync 7cf02a6 --port 8080\n $ resin sync 7cf02a6 --ignore foo,bar', + permission: 'user', + primary: true, + options: [ + { + signature: 'source', + parameter: 'path', + description: 'custom source path', + alias: 's' + }, { + signature: 'ignore', + parameter: 'paths', + description: 'comma delimited paths to ignore when syncing', + alias: 'i' + }, { + signature: 'before', + parameter: 'command', + description: 'execute a command before syncing', + alias: 'b' + }, { + signature: 'exec', + parameter: 'command', + description: 'execute a command after syncing (on the device)', + alias: 'x' + }, { + signature: 'progress', + boolean: true, + description: 'show progress', + alias: 'p' + }, { + signature: 'port', + parameter: 'port', + description: 'ssh port', + alias: 't' + } + ], + action: function(params, options, done) { + var resinSync; + resinSync = require('resin-sync'); + if (options.ignore != null) { + options.ignore = options.ignore.split(','); + } + return resinSync.sync(params.uuid, options).nodeify(done); + } + }; + +}).call(this); diff --git a/build/app.js b/build/app.js index 77bc0980..6036a84f 100644 --- a/build/app.js +++ b/build/app.js @@ -133,6 +133,8 @@ limitations under the License. capitano.command(actions.logs); + capitano.command(actions.sync); + update.notify(); plugins.register(/^resin-plugin-(.+)$/).then(function() { diff --git a/lib/actions/index.coffee b/lib/actions/index.coffee index dd7a1e7c..12619bca 100644 --- a/lib/actions/index.coffee +++ b/lib/actions/index.coffee @@ -28,3 +28,4 @@ module.exports = os: require('./os') settings: require('./settings') config: require('./config') + sync: require('./sync') diff --git a/lib/actions/sync.coffee b/lib/actions/sync.coffee new file mode 100644 index 00000000..033c439e --- /dev/null +++ b/lib/actions/sync.coffee @@ -0,0 +1,83 @@ +### +Copyright 2016 Resin.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +### + +module.exports = + signature: 'sync ' + description: '(beta) sync your changes with a device' + help: ''' + Use this command to sync your local changes to a certain device on the fly. + + You can save all the options mentioned below in a `resin-sync.yml` file, + by using the same option names as keys. For example: + + $ cat $PWD/resin-sync.yml + source: src/ + before: 'echo Hello' + exec: 'python main.py' + ignore: + - .git + - node_modules/ + progress: true + + Notice that explicitly passed command options override the ones set in the configuration file. + + Examples: + + $ resin sync 7cf02a6 + $ resin sync 7cf02a6 --port 8080 + $ resin sync 7cf02a6 --ignore foo,bar + ''' + permission: 'user' + primary: true + options: [ + signature: 'source' + parameter: 'path' + description: 'custom source path' + alias: 's' + , + signature: 'ignore' + parameter: 'paths' + description: 'comma delimited paths to ignore when syncing' + alias: 'i' + , + signature: 'before' + parameter: 'command' + description: 'execute a command before syncing' + alias: 'b' + , + signature: 'exec' + parameter: 'command' + description: 'execute a command after syncing (on the device)' + alias: 'x' + , + signature: 'progress' + boolean: true + description: 'show progress' + alias: 'p' + , + signature: 'port' + parameter: 'port' + description: 'ssh port' + alias: 't' + ] + action: (params, options, done) -> + resinSync = require('resin-sync') + + # TODO: Add comma separated options to Capitano + if options.ignore? + options.ignore = options.ignore.split(',') + + resinSync.sync(params.uuid, options).nodeify(done) diff --git a/lib/app.coffee b/lib/app.coffee index 86fc9f12..09291fa2 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -107,6 +107,9 @@ capitano.command(actions.settings.list) # ---------- Logs Module ---------- capitano.command(actions.logs) +# ---------- Sync Module ---------- +capitano.command(actions.sync) + update.notify() plugins.register(/^resin-plugin-(.+)$/).then -> diff --git a/package.json b/package.json index 60216605..d82db1cf 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "resin-pine": "^1.3.0", "resin-sdk": "^5.2.0", "resin-settings-client": "^3.1.0", + "resin-sync": "^1.0.0", "resin-vcs": "^2.0.0", "rimraf": "^2.4.3", "rindle": "^1.0.0",