-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lagu: Consolidate command data and configuration #497
Comments
Example of duplicated boilerplate / configuration: From export const CUSTOMER: 'customer' = 'customer';
export const NAME: 'name' = 'name';
export const GIT_URL: 'git_url' = 'git_url';
export const OPENSHIFT: 'openshift' = 'openshift';
export const BRANCHES: 'branches' = 'branches';
export const PULLREQUESTS: 'pullrequests' = 'pullrequests';
export const PRODUCTION_ENVIRONMENT: 'production_environment' =
'production_environment';
export const commandOptions = {
[CUSTOMER]: CUSTOMER,
[NAME]: NAME,
[GIT_URL]: GIT_URL,
[OPENSHIFT]: OPENSHIFT,
[BRANCHES]: BRANCHES,
[PULLREQUESTS]: PULLREQUESTS,
[PRODUCTION_ENVIRONMENT]: PRODUCTION_ENVIRONMENT,
};
type OptionalOptions = {
customer?: number,
name?: string,
git_url?: string,
openshift?: number,
branches?: string,
pullrequests?: string,
production_environment?: string,
};
type Options = {
customer: number,
name: string,
git_url: string,
openshift: number,
branches: string,
pullrequests: string,
production_environment: string,
};
yargs
.usage(`$0 ${command} - ${description}`)
.options({
[CUSTOMER]: {
describe: 'Customer id to use for new project',
type: 'number',
alias: 'c',
},
[NAME]: {
describe: 'Name of new project',
type: 'string',
alias: 'n',
},
[GIT_URL]: {
describe: 'Git URL of new project',
type: 'string',
alias: 'u',
},
// ...
inquirer.prompt([
{
type: 'list',
name: CUSTOMER,
message: 'Customer:',
choices: allCustomers,
},
{
type: 'input',
name: NAME,
message: 'Project name:',
},
// ... From export type LagoonConfig = {|
api?: string,
branches?: boolean | RegExp,
customer?: number,
git_url?: string,
openshift?: number,
production_environment?: string,
project?: string,
pullrequests?: boolean | RegExp,
ssh?: string,
token?: string,
|}; |
Looks like the
Maybe we could just use Edit: We could probably also gather Inquirer.js config too if we exported another function per module (would be nice to split up the commands into multiple files per command if possible at this point) and did something in the handler override in yargs visit function we already have in Edit 2: We will also need a solution in the future for global (non-command-specific) configuration (such as |
Consolidate the various types of data and configuration we have for the commands into a common format, that should support integration with:
yargs
.lagoon.yml
configinquirer
Potential strategy
Read in input in the
config/index.js
(priority: CLI args, env vars, config, inquirer) based on what the command needs, and then simplifygetOptions
.Maybe look at some examples of CLI tools that do this (maybe Prettier?) and possibly projects like
yargs-interactive
. For example, this file may be interesting to take a look at.The text was updated successfully, but these errors were encountered: