[cli] Explicitly use vc project vs. vc projects (#8113)

This is a follow-up to #8091 which:

- Makes `vc project` the default command, with `vc projects` aliased to `vc project` (previously it was not clear in the code which one was the "real" command)
- Makes some helper names for `ls` more specific

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
This commit is contained in:
Matthew Stanciu
2022-07-08 11:56:35 -07:00
committed by GitHub
parent 599f8f675c
commit 5a7461dfe3
6 changed files with 28 additions and 27 deletions

View File

@@ -25,8 +25,8 @@ export default new Map([
['logout', 'logout'], ['logout', 'logout'],
['logs', 'logs'], ['logs', 'logs'],
['ls', 'list'], ['ls', 'list'],
['project', 'projects'], ['project', 'project'],
['projects', 'projects'], ['projects', 'project'],
['pull', 'pull'], ['pull', 'pull'],
['remove', 'remove'], ['remove', 'remove'],
['rm', 'remove'], ['rm', 'remove'],

View File

@@ -653,7 +653,7 @@ const main = async () => {
case 'logout': case 'logout':
func = require('./commands/logout').default; func = require('./commands/logout').default;
break; break;
case 'projects': case 'project':
func = require('./commands/project').default; func = require('./commands/project').default;
break; break;
case 'pull': case 'pull':

View File

@@ -1,4 +1,4 @@
export function getDataFromIntro(output: string): { export function pluckIdentifiersFromDeploymentList(output: string): {
project: string | undefined; project: string | undefined;
org: string | undefined; org: string | undefined;
} { } {
@@ -11,7 +11,7 @@ export function getDataFromIntro(output: string): {
}; };
} }
export function parseTable(output: string): string[] { export function parseSpacedTableRow(output: string): string[] {
return output return output
.trim() .trim()
.replace(/ {1} +/g, ',') .replace(/ {1} +/g, ',')

View File

@@ -1323,12 +1323,7 @@ test('[vc projects] should create a project successfully', async t => {
Math.random().toString(36).split('.')[1] Math.random().toString(36).split('.')[1]
}`; }`;
const vc = execa(binaryPath, [ const vc = execa(binaryPath, ['project', 'add', projectName, ...defaultArgs]);
'projects',
'add',
projectName,
...defaultArgs,
]);
await waitForPrompt(vc, chunk => await waitForPrompt(vc, chunk =>
chunk.includes(`Success! Project ${projectName} added`) chunk.includes(`Success! Project ${projectName} added`)
@@ -1339,7 +1334,7 @@ test('[vc projects] should create a project successfully', async t => {
// creating the same project again should succeed // creating the same project again should succeed
const vc2 = execa(binaryPath, [ const vc2 = execa(binaryPath, [
'projects', 'project',
'add', 'add',
projectName, projectName,
...defaultArgs, ...defaultArgs,

View File

@@ -6,7 +6,10 @@ import { useTeams } from '../../mocks/team';
import { defaultProject, useProject } from '../../mocks/project'; import { defaultProject, useProject } from '../../mocks/project';
import { useDeployment } from '../../mocks/deployment'; import { useDeployment } from '../../mocks/deployment';
import { readOutputStream } from '../../helpers/read-output-stream'; import { readOutputStream } from '../../helpers/read-output-stream';
import { parseTable, getDataFromIntro } from '../../helpers/parse-table'; import {
parseSpacedTableRow,
pluckIdentifiersFromDeploymentList,
} from '../../helpers/parse-table';
const fixture = (name: string) => const fixture = (name: string) =>
join(__dirname, '../../fixtures/unit/commands/list', name); join(__dirname, '../../fixtures/unit/commands/list', name);
@@ -34,9 +37,9 @@ describe('list', () => {
const output = await readOutputStream(client); const output = await readOutputStream(client);
const { org } = getDataFromIntro(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseTable(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseTable(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
data.splice(2, 1); data.splice(2, 1);
expect(org).toEqual(team[0].slug); expect(org).toEqual(team[0].slug);
@@ -76,9 +79,9 @@ describe('list', () => {
const output = await readOutputStream(client); const output = await readOutputStream(client);
const { org } = getDataFromIntro(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseTable(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseTable(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
data.splice(2, 1); data.splice(2, 1);
expect(org).toEqual(teamSlug); expect(org).toEqual(teamSlug);

View File

@@ -5,9 +5,12 @@ import { defaultProject, useProject } from '../../mocks/project';
import { client } from '../../mocks/client'; import { client } from '../../mocks/client';
import { Project } from '../../../src/types'; import { Project } from '../../../src/types';
import { readOutputStream } from '../../helpers/read-output-stream'; import { readOutputStream } from '../../helpers/read-output-stream';
import { getDataFromIntro, parseTable } from '../../helpers/parse-table'; import {
pluckIdentifiersFromDeploymentList,
parseSpacedTableRow,
} from '../../helpers/parse-table';
describe('projects', () => { describe('project', () => {
describe('list', () => { describe('list', () => {
it('should list deployments under a user', async () => { it('should list deployments under a user', async () => {
const user = useUser(); const user = useUser();
@@ -19,9 +22,9 @@ describe('projects', () => {
await projects(client); await projects(client);
const output = await readOutputStream(client, 2); const output = await readOutputStream(client, 2);
const { org } = getDataFromIntro(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseTable(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseTable(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
data.pop(); data.pop();
expect(org).toEqual(user.username); expect(org).toEqual(user.username);
@@ -40,9 +43,9 @@ describe('projects', () => {
await projects(client); await projects(client);
const output = await readOutputStream(client, 2); const output = await readOutputStream(client, 2);
const { org } = getDataFromIntro(output.split('\n')[0]); const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseTable(output.split('\n')[2]); const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseTable(output.split('\n')[3]); const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
data.pop(); data.pop();
expect(org).toEqual(team[0].slug); expect(org).toEqual(team[0].slug);