-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7d4d033
Showing
16 changed files
with
2,237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "mklabs", | ||
|
||
"rules": { | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "env" }], | ||
"no-else-return": "off", | ||
"consistent-return": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env node | ||
process.env.DEBUG = process.env.DEBUG || 'now-completions*'; | ||
|
||
const tabtab = require('tabtab'); | ||
const opts = require('minimist')(process.argv.slice(2), { | ||
boolean: ['help', 'version'] | ||
}); | ||
|
||
const completion = require('../lib/completion'); | ||
|
||
const args = opts._; | ||
const run = async () => { | ||
const cmd = args[0]; | ||
|
||
if (opts.help || opts.h) { | ||
return console.log(` | ||
now-completions [options] <command> | ||
Commands: | ||
install-completions | install Enables the completion on user system | ||
`); | ||
} | ||
|
||
// Write your CLI there | ||
|
||
// Here we install for the program `tabtab-test` (this file), with | ||
// completer being the same program. Sometimes, you want to complete | ||
// another program that's where the `completer` option might come handy. | ||
if (cmd === 'install-completion' || cmd === 'install') { | ||
await tabtab.install({ | ||
name: 'now', | ||
completer: 'now-completions' | ||
}); | ||
return; | ||
} | ||
|
||
// The completion command is added automatically by tabtab when the program | ||
// is completed. | ||
if (cmd === 'completion') { | ||
const env = tabtab.parseEnv(process.env); | ||
return completion(env); | ||
} | ||
}; | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const request = require('./request'); | ||
|
||
const deployments = async () => { | ||
const { body } = await request('/now/deployments'); | ||
return body.deployments; | ||
}; | ||
|
||
module.exports = { | ||
deployments | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const untilidfy = require('untildify'); | ||
|
||
/* eslint-disable import/no-dynamic-require, global-require, consistent-return, no-console */ | ||
const auth = () => { | ||
try { | ||
const authJSON = require(untilidfy('~/.now/auth.json')); | ||
return authJSON.credentials[0].token; | ||
} catch (err) { | ||
console.error( | ||
new Error(` | ||
Cannot load token from now auth.json file. | ||
Make sure to run "now login" once before using this completion. | ||
`) | ||
); | ||
} | ||
}; | ||
|
||
module.exports = auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const commands = [ | ||
{ name: 'deploy', description: 'Performs a deployment (default)' }, | ||
{ name: 'help', description: 'Displays complete help for [cmd]' }, | ||
{ name: 'list', description: 'Lists deployments' }, | ||
{ name: 'remove', description: 'Removes a deployment' }, | ||
{ name: 'alias', description: 'Configures aliases for deployments' }, | ||
{ name: 'domains', description: 'Manages your domain names' }, | ||
{ name: 'certs', description: 'Manages your SSL certificates' }, | ||
{ name: 'dns', description: 'Manages your DNS records' }, | ||
{ name: 'secrets', description: 'Manages your secret environment variables' }, | ||
{ | ||
name: 'billing', | ||
description: 'Manages your credit carts and billing methods' | ||
}, | ||
{ name: 'upgrade', description: 'Upgrades or downgrades your plan' }, | ||
{ name: 'teams', description: 'Manages your teams' }, | ||
{ name: 'logs', description: 'Displays the logs for a deployment' }, | ||
{ name: 'scale', description: 'Scales the instance count of a deployment' }, | ||
{ name: 'login', description: 'Logs into your account or creates a new one' }, | ||
{ name: 'logout', description: 'Logs out of your account' }, | ||
{ name: 'whoami', description: 'Displays the currently logged in username' }, | ||
{ | ||
name: 'inspect', | ||
description: 'Displays information related to a deployment' | ||
} | ||
]; | ||
|
||
const aliases = { | ||
list: ['ls'], | ||
remove: ['rm'], | ||
alias: ['ln', 'aliases'], | ||
domains: ['domain'], | ||
certs: ['cert'], | ||
secrets: ['secret'], | ||
billing: ['cc'], | ||
upgrade: ['downgrade'], | ||
teams: ['team', 'switch'], | ||
logs: ['log'] | ||
}; | ||
|
||
// Add aliases to available sub commands | ||
/* eslint-disable guard-for-in */ | ||
for (const alias in aliases) { | ||
const items = aliases[alias]; | ||
|
||
for (const item of items) { | ||
const { description } = commands.find(cmd => cmd.name === alias); | ||
commands.push({ name: item, description }); | ||
} | ||
} | ||
|
||
module.exports = commands; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const tabtab = require('tabtab'); | ||
|
||
const commands = require('./commands'); | ||
const options = require('./options'); | ||
const subcommands = require('./subcommands'); | ||
|
||
const completion = async env => { | ||
/* eslint-disable consistent-return */ | ||
if (!env.complete) return; | ||
|
||
const subcmd = subcommands[env.prev]; | ||
|
||
if (!subcmd) { | ||
return tabtab.log([...commands, ...options]); | ||
} | ||
|
||
// We have a completion handler for this previous word, simply execute | ||
await subcmd(env); | ||
}; | ||
|
||
module.exports = completion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const options = [ | ||
'-h', | ||
'--help', | ||
'-v', | ||
'--version', | ||
'-n', | ||
'--name', | ||
'-A', | ||
'--local-config', | ||
'-Q', | ||
'--global-config', | ||
'-d', | ||
'--debug', | ||
'-f', | ||
'--force', | ||
'-t', | ||
'--token', | ||
'-l', | ||
'--links', | ||
'-p', | ||
'--public', | ||
'-e', | ||
'--env', | ||
'-b', | ||
'--build-env', | ||
'-E', | ||
'--dotenv', | ||
'-C', | ||
'--no-clipboard', | ||
'-N', | ||
'--forward-npm', | ||
'--session-affinity', | ||
'-T', | ||
'--team', | ||
'--regions', | ||
'--no-verify' | ||
]; | ||
|
||
module.exports = options; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const got = require('got'); | ||
const pkg = require('../package.json'); | ||
const auth = require('./auth'); | ||
|
||
const request = url => { | ||
const token = auth(); | ||
if (!token) return Promise.resolve(); | ||
|
||
const headers = { | ||
'user-agent': `${pkg.name}/${pkg.version} (${pkg.homepage})`, | ||
Authorization: `Bearer ${token}` | ||
}; | ||
|
||
return got(url, { | ||
baseUrl: 'https://api.zeit.co/v2', | ||
json: true, | ||
headers | ||
}); | ||
}; | ||
|
||
module.exports = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const ls = require('./ls'); | ||
const logs = require('./logs'); | ||
|
||
module.exports = { | ||
ls, | ||
list: ls, | ||
logs, | ||
log: logs, | ||
inspect: logs | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const tabtab = require('tabtab'); | ||
const { deployments } = require('../api'); | ||
|
||
const logs = async env => { | ||
if (env.prev === 'logs' || env.prev === 'log') { | ||
if (env.last === '-') { | ||
return tabtab.log([ | ||
'-h', | ||
'-a', | ||
'-A', | ||
'-Q', | ||
'-d', | ||
'-f', | ||
'-n', | ||
'-q', | ||
'-t', | ||
'-T', | ||
'-o' | ||
]); | ||
} else if (env.last === '--') { | ||
return tabtab.log([ | ||
'--help', | ||
'--all', | ||
'--local-config=', | ||
'--global-config=', | ||
'--debug', | ||
'--follow', | ||
'--query=', | ||
'--token=', | ||
'--since=', | ||
'--until=', | ||
'--team', | ||
'--output=' | ||
]); | ||
} | ||
} else if (env.prev === 'inspect') { | ||
if (env.last === '-' || env.last === '--') { | ||
return tabtab.log([ | ||
'-h', | ||
'--help', | ||
'-A', | ||
'--local-config=', | ||
'-Q', | ||
'--global-config=', | ||
'-d', | ||
'--debug', | ||
'-T', | ||
'--team' | ||
]); | ||
} | ||
} | ||
|
||
const urls = (await deployments()).map(d => d.url); | ||
tabtab.log(urls); | ||
}; | ||
|
||
module.exports = logs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const tabtab = require('tabtab'); | ||
const { deployments } = require('../api'); | ||
|
||
const ls = async env => { | ||
const names = (await deployments()).map(d => d.name); | ||
tabtab.log(names); | ||
}; | ||
|
||
module.exports = ls; |
Oops, something went wrong.