├── .gitignore ├── README.md ├── bin └── vgm ├── package.json ├── src ├── add.js ├── box.js ├── configstore.js ├── index.js ├── list.js ├── path.js └── remove.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant Manager 2 | 3 | A little command line tool to manage many vagrant boxes without changing working directory. 4 | 5 | ## Installation 6 | 7 | ```bash 8 | $ npm install -g vgm 9 | ``` 10 | 11 | ## Getting Started 12 | 13 | 1. Add your vagrant boxes to the manager with the following command: 14 | 15 | ```bash 16 | $ vgm add 17 | ``` 18 | 19 | Where `` - is any convenient name that you would like to use for your box 20 | and `` is path to where your `Vagrantfile` is stored. 21 | 22 | 2. Run vagrant commands like this: 23 | 24 | ```bash 25 | $ vgm status 26 | ``` 27 | 28 | This should show you your box's status. 29 | 30 | ## Commands 31 | 32 | ### `vgm add [path]` 33 | 34 | Adds virtual machine to the manager 35 | 36 | #### Arguments: 37 | 38 | - `name` - any convenient name for your virtual machine 39 | - `path` _(optional)_ - path to Vagrantfile directory, if not present `vgm` will use path to current directory 40 | 41 | ### `vgm remove ` 42 | 43 | Removes virtual machine from the manager configuration 44 | 45 | #### Arguments: 46 | 47 | - `name` - name of the machine that you want to remove 48 | 49 | ### `vgm list` 50 | 51 | Outputs list of all registered vitrual machines. 52 | 53 | ### `vgm [cmd]` 54 | 55 | Runs vagrant command on a machine 56 | 57 | #### Arguments: 58 | 59 | - `name` - name of the machine that you want to run the command on 60 | - `cmd` _(optional)_ - vagrant command, if not present `vgm` will assume `status` command 61 | -------------------------------------------------------------------------------- /bin/vgm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | require('../src')(); 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vgm", 3 | "version": "1.0.1", 4 | "description": "Vagrant Manager", 5 | "main": "src/index.js", 6 | "bin": { 7 | "vgm": "./bin/vgm" 8 | }, 9 | "preferGlobal": true, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/MunGell/vgm.git" 16 | }, 17 | "keywords": [ 18 | "vagrant", 19 | "cli", 20 | "manager" 21 | ], 22 | "author": "Shmavon Gazanchyan ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/MunGell/vgm/issues" 26 | }, 27 | "homepage": "https://github.com/MunGell/vgm#readme", 28 | "dependencies": { 29 | "chalk": "^1.1.3", 30 | "cli-table": "^0.3.1", 31 | "commander": "^2.9.0", 32 | "configstore": "^2.1.0", 33 | "path-exists": "^3.0.0" 34 | }, 35 | "engines": { 36 | "node": ">=4.0.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/add.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const configstore = require('./configstore'); 3 | const pathUtils = require('./path'); 4 | 5 | module.exports = function (name, vagrantpath) { 6 | vagrantpath = vagrantpath ? pathUtils.getPathOnly(vagrantpath) : pathUtils.getCurrentPath(); 7 | 8 | if (configstore.has(name)) { 9 | console.error(chalk.red('Box with name %s is already registered in %s'), name, configstore.get(name)); 10 | } else if (!pathUtils.hasVagrantSetup(vagrantpath)) { 11 | console.error(chalk.red('There is no Vagrant setup in %s'), vagrantpath); 12 | } else { 13 | configstore.set(name, vagrantpath); 14 | if (configstore.has(name)) { 15 | console.info(chalk.green('Box called \'%s\' was successfully added to Vagrant Manager'), name); 16 | } else { 17 | console.error(chalk.green('We were not able to save the configuration file')); 18 | } 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /src/box.js: -------------------------------------------------------------------------------- 1 | const spawn = require('child_process').spawn; 2 | const configstore = require('./configstore'); 3 | 4 | module.exports = function (name, cmd) { 5 | cmd = cmd.length ? cmd : ['status']; 6 | 7 | process.stdin.pause(); 8 | 9 | if (process.stdin.isTTY) { 10 | process.stdin.setRawMode(false); 11 | } 12 | 13 | var options = { 14 | "cwd": configstore.get(name), 15 | 'stdio': 'inherit' 16 | }, 17 | proc = spawn('vagrant', cmd, options); 18 | 19 | return proc.on('exit', function () { 20 | if (process.stdin.isTTY) { 21 | process.stdin.setRawMode(); 22 | } 23 | process.stdin.resume(); 24 | return process.exit(); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /src/configstore.js: -------------------------------------------------------------------------------- 1 | const Configstore = require('configstore'); 2 | const pkg = require('../package.json'); 3 | 4 | module.exports = new Configstore(pkg.name); 5 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const program = require('commander'); 2 | const pkg = require('../package.json'); 3 | const listCmd = require('./list'); 4 | const addCmd = require('./add'); 5 | const removeCmd = require('./remove'); 6 | const boxCmd = require('./box'); 7 | 8 | module.exports = function () { 9 | program.version(pkg.version); 10 | 11 | program 12 | .command('list') 13 | .description('show list of all managed vagrant boxes') 14 | .action(listCmd); 15 | 16 | program 17 | .command('add [path]') 18 | .description('add box to vagrant manager (vgm)') 19 | .action(addCmd); 20 | 21 | program 22 | .command('remove ') 23 | .alias('rm') 24 | .description('remove box from vagrant manager (vgm)') 25 | .action(removeCmd); 26 | 27 | program 28 | .command('* [cmd...]') 29 | .description('execute box-related commands') 30 | .action(boxCmd); 31 | 32 | program.parse(process.argv); 33 | 34 | if (!program.args.length) program.help(); 35 | }; 36 | -------------------------------------------------------------------------------- /src/list.js: -------------------------------------------------------------------------------- 1 | const Table = require('cli-table'); 2 | const configstore = require('./configstore'); 3 | 4 | module.exports = function () { 5 | var table = new Table({ 6 | head: ['Name', 'Path'] 7 | }); 8 | 9 | for (var box in configstore.all) { 10 | table.push([box, configstore.get(box)]); 11 | } 12 | 13 | console.log(table.toString()); 14 | }; 15 | -------------------------------------------------------------------------------- /src/path.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pathExists = require('path-exists'); 3 | 4 | module.exports = { 5 | hasVagrantSetup: function (p) { 6 | var vagrantFilePath = /Vagrantfile$/.test(p) ? p : path.join(p, 'Vagrantfile'); 7 | return pathExists.sync(vagrantFilePath); 8 | }, 9 | getPathOnly: function (p) { 10 | return /Vagrantfile$/.test(p) ? p.slice(0, -11) : p 11 | }, 12 | getCurrentPath: function () { 13 | return process.cwd(); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /src/remove.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const configstore = require('./configstore'); 3 | 4 | module.exports = function (name) { 5 | if (!configstore.has(name)) { 6 | console.error(chalk.red('This box is not registered with Vagrant Manager')); 7 | } else { 8 | configstore.del(name); 9 | if (!configstore.has(name)) { 10 | console.info(chalk.green('Box called \'%s\' was successfully removed from Vagrant Manager'), name); 11 | } else { 12 | console.error(chalk.red('We were not able to save the configuration file')); 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | ansi-regex@^2.0.0: 4 | version "2.0.0" 5 | resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.0.0.tgz#c5061b6e0ef8a81775e50f5d66151bf6bf371107" 6 | 7 | ansi-styles@^2.2.1: 8 | version "2.2.1" 9 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" 10 | 11 | chalk@^1.1.3: 12 | version "1.1.3" 13 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" 14 | dependencies: 15 | ansi-styles "^2.2.1" 16 | escape-string-regexp "^1.0.2" 17 | has-ansi "^2.0.0" 18 | strip-ansi "^3.0.0" 19 | supports-color "^2.0.0" 20 | 21 | cli-table@^0.3.1: 22 | version "0.3.1" 23 | resolved "https://registry.yarnpkg.com/cli-table/-/cli-table-0.3.1.tgz#f53b05266a8b1a0b934b3d0821e6e2dc5914ae23" 24 | dependencies: 25 | colors "1.0.3" 26 | 27 | colors@1.0.3: 28 | version "1.0.3" 29 | resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" 30 | 31 | commander@^2.9.0: 32 | version "2.9.0" 33 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" 34 | dependencies: 35 | graceful-readlink ">= 1.0.0" 36 | 37 | configstore@^2.1.0: 38 | version "2.1.0" 39 | resolved "https://registry.yarnpkg.com/configstore/-/configstore-2.1.0.tgz#737a3a7036e9886102aa6099e47bb33ab1aba1a1" 40 | dependencies: 41 | dot-prop "^3.0.0" 42 | graceful-fs "^4.1.2" 43 | mkdirp "^0.5.0" 44 | object-assign "^4.0.1" 45 | os-tmpdir "^1.0.0" 46 | osenv "^0.1.0" 47 | uuid "^2.0.1" 48 | write-file-atomic "^1.1.2" 49 | xdg-basedir "^2.0.0" 50 | 51 | dot-prop@^3.0.0: 52 | version "3.0.0" 53 | resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177" 54 | dependencies: 55 | is-obj "^1.0.0" 56 | 57 | escape-string-regexp@^1.0.2: 58 | version "1.0.5" 59 | resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" 60 | 61 | graceful-fs@^4.1.2: 62 | version "4.1.9" 63 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.9.tgz#baacba37d19d11f9d146d3578bc99958c3787e29" 64 | 65 | "graceful-readlink@>= 1.0.0": 66 | version "1.0.1" 67 | resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" 68 | 69 | has-ansi@^2.0.0: 70 | version "2.0.0" 71 | resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" 72 | dependencies: 73 | ansi-regex "^2.0.0" 74 | 75 | imurmurhash@^0.1.4: 76 | version "0.1.4" 77 | resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" 78 | 79 | is-obj@^1.0.0: 80 | version "1.0.1" 81 | resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f" 82 | 83 | minimist@0.0.8: 84 | version "0.0.8" 85 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" 86 | 87 | mkdirp@^0.5.0: 88 | version "0.5.1" 89 | resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" 90 | dependencies: 91 | minimist "0.0.8" 92 | 93 | object-assign@^4.0.1: 94 | version "4.1.0" 95 | resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" 96 | 97 | os-homedir@^1.0.0: 98 | version "1.0.2" 99 | resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" 100 | 101 | os-tmpdir@^1.0.0: 102 | version "1.0.2" 103 | resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" 104 | 105 | osenv@^0.1.0: 106 | version "0.1.3" 107 | resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.3.tgz#83cf05c6d6458fc4d5ac6362ea325d92f2754217" 108 | dependencies: 109 | os-homedir "^1.0.0" 110 | os-tmpdir "^1.0.0" 111 | 112 | path-exists@^3.0.0: 113 | version "3.0.0" 114 | resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" 115 | 116 | slide@^1.1.5: 117 | version "1.1.6" 118 | resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" 119 | 120 | strip-ansi@^3.0.0: 121 | version "3.0.1" 122 | resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" 123 | dependencies: 124 | ansi-regex "^2.0.0" 125 | 126 | supports-color@^2.0.0: 127 | version "2.0.0" 128 | resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" 129 | 130 | uuid@^2.0.1: 131 | version "2.0.3" 132 | resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" 133 | 134 | write-file-atomic@^1.1.2: 135 | version "1.2.0" 136 | resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-1.2.0.tgz#14c66d4e4cb3ca0565c28cf3b7a6f3e4d5938fab" 137 | dependencies: 138 | graceful-fs "^4.1.2" 139 | imurmurhash "^0.1.4" 140 | slide "^1.1.5" 141 | 142 | xdg-basedir@^2.0.0: 143 | version "2.0.0" 144 | resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-2.0.0.tgz#edbc903cc385fc04523d966a335504b5504d1bd2" 145 | dependencies: 146 | os-homedir "^1.0.0" 147 | 148 | --------------------------------------------------------------------------------