@heroku-cli/command
Advanced tools
Comparing version 8.1.17 to 8.1.18
@@ -0,1 +1,9 @@ | ||
<a name="8.1.18"></a> | ||
## [8.1.18](https://github.com/heroku/heroku-cli-command/compare/v8.1.17...v8.1.18) (2018-05-21) | ||
### Bug Fixes | ||
* consolidate completions ([#38](https://github.com/heroku/heroku-cli-command/issues/38)) ([da45bf8](https://github.com/heroku/heroku-cli-command/commit/da45bf8)) | ||
<a name="8.1.17"></a> | ||
@@ -2,0 +10,0 @@ ## [8.1.17](https://github.com/heroku/heroku-cli-command/compare/v8.1.16...v8.1.17) (2018-05-15) |
import { flags } from '@oclif/command'; | ||
import * as Config from '@oclif/config'; | ||
export { AppCompletion, RemoteCompletion } from './flags/app'; | ||
export declare const oneDay: number; | ||
@@ -8,5 +7,6 @@ export declare const herokuGet: (resource: string, ctx: { | ||
}) => Promise<string[]>; | ||
export declare const BuildpackCompletion: flags.ICompletion; | ||
export declare const AppCompletion: flags.ICompletion; | ||
export declare const AppAddonCompletion: flags.ICompletion; | ||
export declare const AppDynoCompletion: flags.ICompletion; | ||
export declare const BuildpackCompletion: flags.ICompletion; | ||
export declare const DynoSizeCompletion: flags.ICompletion; | ||
@@ -17,2 +17,3 @@ export declare const FileCompletion: flags.ICompletion; | ||
export declare const RegionCompletion: flags.ICompletion; | ||
export declare const RemoteCompletion: flags.ICompletion; | ||
export declare const RoleCompletion: flags.ICompletion; | ||
@@ -19,0 +20,0 @@ export declare const ScopeCompletion: flags.ICompletion; |
@@ -5,5 +5,3 @@ "use strict"; | ||
const deps_1 = require("./deps"); | ||
var app_1 = require("./flags/app"); | ||
exports.AppCompletion = app_1.AppCompletion; | ||
exports.RemoteCompletion = app_1.RemoteCompletion; | ||
const git_1 = require("./git"); | ||
exports.oneDay = 60 * 60 * 24; | ||
@@ -17,16 +15,7 @@ exports.herokuGet = async (resource, ctx) => { | ||
}; | ||
exports.BuildpackCompletion = { | ||
skipCache: true, | ||
options: async () => { | ||
return [ | ||
'heroku/ruby', | ||
'heroku/nodejs', | ||
'heroku/clojure', | ||
'heroku/python', | ||
'heroku/java', | ||
'heroku/gradle', | ||
'heroku/scala', | ||
'heroku/php', | ||
'heroku/go', | ||
]; | ||
exports.AppCompletion = { | ||
cacheDuration: exports.oneDay, | ||
options: async (ctx) => { | ||
let apps = await exports.herokuGet('apps', ctx); | ||
return apps; | ||
}, | ||
@@ -54,2 +43,18 @@ }; | ||
}; | ||
exports.BuildpackCompletion = { | ||
skipCache: true, | ||
options: async () => { | ||
return [ | ||
'heroku/ruby', | ||
'heroku/nodejs', | ||
'heroku/clojure', | ||
'heroku/python', | ||
'heroku/java', | ||
'heroku/gradle', | ||
'heroku/scala', | ||
'heroku/php', | ||
'heroku/go', | ||
]; | ||
}, | ||
}; | ||
exports.DynoSizeCompletion = { | ||
@@ -108,2 +113,9 @@ cacheDuration: exports.oneDay * 90, | ||
}; | ||
exports.RemoteCompletion = { | ||
skipCache: true, | ||
options: async () => { | ||
let remotes = git_1.getGitRemotes(git_1.configRemote()); | ||
return remotes.map(r => r.remote); | ||
}, | ||
}; | ||
exports.RoleCompletion = { | ||
@@ -110,0 +122,0 @@ skipCache: true, |
import { flags } from '@oclif/command'; | ||
export declare const AppCompletion: flags.ICompletion; | ||
export declare const app: flags.Definition<string>; | ||
export declare const RemoteCompletion: flags.ICompletion; | ||
export declare const remote: flags.Definition<string>; |
@@ -7,3 +7,2 @@ "use strict"; | ||
const git_1 = require("../git"); | ||
const vars_1 = require("../vars"); | ||
class MultipleRemotesError extends errors_1.CLIError { | ||
@@ -23,12 +22,5 @@ constructor(gitRemotes) { | ||
} | ||
exports.AppCompletion = { | ||
cacheDuration: completions_1.oneDay, | ||
options: async (ctx) => { | ||
let apps = await completions_1.herokuGet('apps', ctx); | ||
return apps; | ||
}, | ||
}; | ||
exports.app = command_1.flags.build({ | ||
char: 'a', | ||
completion: exports.AppCompletion, | ||
completion: completions_1.AppCompletion, | ||
description: 'app to run command against', | ||
@@ -39,3 +31,3 @@ default: ({ options, flags }) => { | ||
return envApp; | ||
let gitRemotes = getGitRemotes(flags.remote || configRemote()); | ||
let gitRemotes = git_1.getGitRemotes(flags.remote || git_1.configRemote()); | ||
if (gitRemotes.length === 1) | ||
@@ -51,46 +43,6 @@ return gitRemotes[0].app; | ||
}); | ||
exports.RemoteCompletion = { | ||
skipCache: true, | ||
options: async () => { | ||
let remotes = getGitRemotes(configRemote()); | ||
return remotes.map(r => r.remote); | ||
}, | ||
}; | ||
exports.remote = command_1.flags.build({ | ||
char: 'r', | ||
completion: exports.RemoteCompletion, | ||
completion: completions_1.RemoteCompletion, | ||
description: 'git remote of app to use', | ||
}); | ||
function configRemote() { | ||
let git = new git_1.Git(); | ||
try { | ||
return git.exec('config heroku.remote').trim(); | ||
} | ||
catch (_a) { } | ||
} | ||
function getGitRemotes(onlyRemote) { | ||
let git = new git_1.Git(); | ||
let appRemotes = []; | ||
let remotes; | ||
try { | ||
remotes = git.remotes; | ||
} | ||
catch (_a) { | ||
return []; | ||
} | ||
for (let remote of remotes) { | ||
if (onlyRemote && remote.name !== onlyRemote) | ||
continue; | ||
for (let prefix of vars_1.vars.gitPrefixes) { | ||
const suffix = '.git'; | ||
let match = remote.url.match(`${prefix}(.*)${suffix}`); | ||
if (!match) | ||
continue; | ||
appRemotes.push({ | ||
app: match[1], | ||
remote: remote.name, | ||
}); | ||
} | ||
} | ||
return appRemotes; | ||
} |
@@ -9,1 +9,7 @@ export interface IGitRemote { | ||
} | ||
export declare function configRemote(): string | undefined; | ||
export interface IGitRemotes { | ||
remote: string; | ||
app: string; | ||
} | ||
export declare function getGitRemotes(onlyRemote: string | undefined): IGitRemotes[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = require("@oclif/errors"); | ||
const vars_1 = require("./vars"); | ||
class Git { | ||
@@ -31,1 +32,36 @@ get remotes() { | ||
exports.Git = Git; | ||
function configRemote() { | ||
let git = new Git(); | ||
try { | ||
return git.exec('config heroku.remote').trim(); | ||
} | ||
catch (_a) { } | ||
} | ||
exports.configRemote = configRemote; | ||
function getGitRemotes(onlyRemote) { | ||
let git = new Git(); | ||
let appRemotes = []; | ||
let remotes; | ||
try { | ||
remotes = git.remotes; | ||
} | ||
catch (_a) { | ||
return []; | ||
} | ||
for (let remote of remotes) { | ||
if (onlyRemote && remote.name !== onlyRemote) | ||
continue; | ||
for (let prefix of vars_1.vars.gitPrefixes) { | ||
const suffix = '.git'; | ||
let match = remote.url.match(`${prefix}(.*)${suffix}`); | ||
if (!match) | ||
continue; | ||
appRemotes.push({ | ||
app: match[1], | ||
remote: remote.name, | ||
}); | ||
} | ||
} | ||
return appRemotes; | ||
} | ||
exports.getGitRemotes = getGitRemotes; |
{ | ||
"name": "@heroku-cli/command", | ||
"description": "base class for Heroku CLI commands", | ||
"version": "8.1.17", | ||
"version": "8.1.18", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/heroku-cli-command/issues", |
52867
1181