diff --git a/README.md b/README.md index 5c51e75..6e8df16 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,18 @@ All subcommands supported by `chip` can be viewed by running `chip help`: chip Commands: - chip sync [services..] Clone or pull repos for services in - project - chip checkout [services..] Checkout a git branch for services in - project - chip status [services..] Show git status for services in project - chip install [services..] Install dependencies for services in - project - chip start [services..] Start services in project - chip stop [services..] Stop services in project - chip restart [services..] Stop and restart services in project - chip logs [services..] View logs for services in project - chip list List all services in project + chip sync [services|tags..] Clone or pull repos for services in + project + chip checkout [services|tags..] Checkout a git branch for services in + project + chip status [services|tags..] Show git status for services in project + chip install [services|tags..] Install dependencies for services in + project + chip start [services|tags..] Start services in project + chip stop [services|tags..] Stop services in project + chip restart [services|tags..] Stop and restart services in project + chip logs [services|tags..] View logs for services in project + chip list List all services in project ``` ## Sample Project @@ -83,11 +83,15 @@ services: repo: 'git@github.com:QDivision/sandwich-ui.git' install: 'yarn install' run: 'yarn start' + tags: + - sandwich sandwich-api: repo: 'git@github.com:QDivision/sandwich-api.git' install: 'mvn clean package -D maven.test.skip=true' run: 'mvn spring-boot:run -D spring-boot.run.profiles=local' + tags: + - sandwich ingredient-api: repo: 'git@github.com:QDivision/ingredient-api.git' diff --git a/src/cli.ts b/src/cli.ts index eb280cd..d2a4d8c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -16,7 +16,7 @@ import { cleanNames } from './utils/strings'; yargs .command<{ services: string[] }>( - 'sync [services..]', + 'sync [services|tags..]', 'Clone or pull repos for services in project', (yargs) => yargs.positional('services', { describe: 'service names' }), handleErrors(async ({ services }) => { @@ -25,7 +25,7 @@ yargs }), ) .command<{ branch: string; services: string[] }>( - 'checkout [services..]', + 'checkout [services|tags..]', 'Checkout a git branch for services in project', (yargs) => yargs @@ -38,7 +38,7 @@ yargs }), ) .command<{ services: string[] }>( - 'status [services..]', + 'status [services|tags..]', 'Show git status for services in project', (yargs) => yargs.positional('services', { describe: 'service names' }), handleErrors(async ({ services }) => { @@ -48,7 +48,7 @@ yargs }), ) .command<{ services: string[] }>( - 'install [services..]', + 'install [services|tags..]', 'Install dependencies for services in project', (yargs) => yargs.positional('services', { describe: 'service names' }), handleErrors(async ({ services }) => { @@ -58,7 +58,7 @@ yargs }), ) .command<{ services: string[] }>( - 'start [services..]', + 'start [services|tags..]', 'Start services in project', (yargs) => yargs.positional('services', { describe: 'service names' }), handleErrors(async ({ services }) => { @@ -68,7 +68,7 @@ yargs }), ) .command<{ services: string[]; remove: boolean }>( - 'stop [services..]', + 'stop [services|tags..]', 'Stop services in project', (yargs) => yargs.positional('services', { describe: 'service names' }).option('r', { @@ -84,7 +84,7 @@ yargs }), ) .command<{ services: string[]; remove: boolean }>( - 'restart [services..]', + 'restart [services|tags..]', 'Stop and restart services in project', (yargs) => yargs.positional('services', { describe: 'service names' }).option('r', { @@ -100,7 +100,7 @@ yargs }), ) .command<{ services: string[] }>( - 'logs [services..]', + 'logs [services|tags..]', 'View logs for services in project', (yargs) => yargs.positional('services', { describe: 'service names' }), handleErrors(async ({ services }) => { diff --git a/src/subcommands/list.ts b/src/subcommands/list.ts index 10912a7..1dd2199 100644 --- a/src/subcommands/list.ts +++ b/src/subcommands/list.ts @@ -17,6 +17,7 @@ const dockerServices = async () => { status ?? '', ' 🐳', '', + '', ]); }; @@ -32,10 +33,11 @@ export const listServices = async () => { bold('STATUS'), bold('PID'), bold('BRANCH'), + bold('TAGS'), ], ]; - for (const { name, run = '' } of services) { + for (const { name, run = '', tags = [] } of services) { const { pid, startTime } = activeProcesses[name] || {}; const exists = !!pid; @@ -59,6 +61,8 @@ export const listServices = async () => { } } + const allTags = tags.join(', ') || ''; + // prettier-ignore tableData.push([ name, @@ -66,6 +70,7 @@ export const listServices = async () => { status, exists ? String(pid) : '', await git.activeBranch(name), + allTags.substring(0, 30) + (allTags.length > 30 ? '...' : ''), ]); } @@ -82,6 +87,7 @@ export const listServices = async () => { 2: { alignment: 'left' }, 3: { alignment: 'left' }, 4: { alignment: 'left' }, + 5: { alignment: 'left' }, }, }).trim(), ); diff --git a/src/utils/config.ts b/src/utils/config.ts index d659244..9690a0c 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -13,7 +13,8 @@ export interface ChipConfig { install?: string; run?: string; env?: { [envVar: string]: string }; - } + tags?: string[]; + } | undefined; }; } @@ -60,6 +61,7 @@ export const readServices = async ( run?: string; env: { [envVar: string]: string }; secrets: { [name: string]: string }; + tags?: string[]; }[] > => { const config = await readConfig(); @@ -75,7 +77,10 @@ export const readServices = async ( ); return whitelist.length > 0 - ? allServices.filter((service) => whitelist.includes(service.name)) + ? [...new Set([ + ...allServices.filter(service => whitelist.includes(service.name)), + ...allServices.filter(service => service.tags?.some(tag => whitelist.includes(tag))), + ])] : allServices; };