Skip to content
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

feat: concise flag on status to omit ignored files #382

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{
"command": "force:source:beta:status",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "json", "local", "loglevel", "remote", "targetusername"]
"flags": ["apiversion", "concise", "json", "local", "loglevel", "remote", "targetusername"]
},
{
"command": "force:source:beta:tracking:clear",
Expand Down
3 changes: 2 additions & 1 deletion messages/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"local": "list the changes that have been made locally",
"localLong": "Lists the changes that have been made locally.",
"remote": "list the changes that have been made in the scratch org",
"remoteLong": "Lists the changes that have been made in the scratch org."
"remoteLong": "Lists the changes that have been made in the scratch org.",
"concise": "show only the changes that will be pushed or pulled; omits files that are forceignored"
},
"humanSuccess": "Source Status",
"noResults": "No local or remote changes found."
Expand Down
10 changes: 9 additions & 1 deletion src/commands/force/source/beta/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default class Status extends SfdxCommand {
longDescription: messages.getMessage('flags.remoteLong'),
exclusive: ['local'],
}),
concise: flags.builtin({
description: messages.getMessage('flags.concise'),
}),
};
protected static requiresUsername = true;
protected static requiresProject = true;
Expand Down Expand Up @@ -71,7 +74,12 @@ export default class Status extends SfdxCommand {
}

protected formatResult(): StatusResult[] {
const formatter = new StatusFormatter(this.logger, this.ux, {}, this.results);
const formatter = new StatusFormatter(
this.logger,
this.ux,
{ concise: this.flags.concise as boolean },
this.results
);

if (!this.flags.json) {
formatter.display();
Expand Down
11 changes: 8 additions & 3 deletions src/formatters/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import * as path from 'path';
import { UX } from '@salesforce/command';
import { Logger } from '@salesforce/core';
import { FileResponse, Failures, Successes } from '@salesforce/source-deploy-retrieve';
import { getBoolean, getNumber } from '@salesforce/ts-types';
import { getNumber } from '@salesforce/ts-types';

export interface ResultFormatterOptions {
verbose?: boolean;
quiet?: boolean;
waitTime?: number;
concise?: boolean;
}

export function toArray<T>(entryOrArray: T | T[] | undefined): T[] {
Expand Down Expand Up @@ -42,11 +43,15 @@ export abstract class ResultFormatter {
}

public isVerbose(): boolean {
return getBoolean(this.options, 'verbose', false);
return this.options.verbose ?? false;
}

public isQuiet(): boolean {
return getBoolean(this.options, 'quiet', false);
return this.options.quiet ?? false;
}

public isConcise(): boolean {
return this.options.concise ?? false;
}

// Sort by type > filePath > fullName
Expand Down
3 changes: 3 additions & 0 deletions src/formatters/statusFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class StatusFormatter extends ResultFormatter {
}

public display(): void {
if (this.options.concise) {
this.statusRows = this.statusRows.filter((row) => !row.ignored);
}
if (this.statusRows.length === 0) {
this.ux.log(messages.getMessage('noResults'));
return;
Expand Down
85 changes: 85 additions & 0 deletions test/formatters/statusResultFormatter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Logger } from '@salesforce/core';
import { UX } from '@salesforce/command';
import { stubInterface } from '@salesforce/ts-sinon';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { StatusResult, StatusFormatter } from '../../src/formatters/statusFormatter';

const fakeResult: StatusResult[] = [
{
fullName: 'ignoredProfile',
type: 'Profile',
origin: 'Remote',
ignored: true,
actualState: 'Add',
state: 'Remote Add',
},
{
fullName: 'regularProfile',
type: 'Profile',
origin: 'Remote',
ignored: false,
actualState: 'Add',
state: 'Remote Add',
},
];

describe('status results', () => {
const sandbox = sinon.createSandbox();
let ux;
const logger = Logger.childFromRoot('retrieveTestLogger').useMemoryLogging();
let logStub: sinon.SinonStub;
let tableStub: sinon.SinonStub;

beforeEach(() => {
logStub = sandbox.stub();
tableStub = sandbox.stub();

ux = stubInterface<UX>(sandbox, {
log: logStub,
table: tableStub,
});
});

afterEach(() => {
sandbox.restore();
});

it('returns expected json', () => {
const formatter = new StatusFormatter(logger, ux, {}, fakeResult);
expect(formatter.getJson()).deep.equal(fakeResult);
});

describe('human display', () => {
it('includes ignored files without the concise option', () => {
const formatter = new StatusFormatter(logger, ux, { concise: false }, fakeResult);
formatter.display();
expect(tableStub.callCount).to.equal(1);
expect(tableStub.firstCall.args[0]).to.have.equal(fakeResult);
});
it('omits ignored files with the concise option', () => {
const formatter = new StatusFormatter(logger, ux, { concise: true }, fakeResult);
formatter.display();
expect(tableStub.callCount).to.equal(1);
expect(tableStub.firstCall.args[0]).to.deep.equal([fakeResult[1]]);
});
it('shows no results when there are none', () => {
const formatter = new StatusFormatter(logger, ux, { concise: false }, []);
formatter.display();
expect(logStub.callCount).to.equal(1);
expect(logStub.firstCall.args[0]).to.contain('No local or remote changes found.');
});
it('shows no results when there are none because concise omitted them', () => {
const formatter = new StatusFormatter(logger, ux, { concise: true }, [fakeResult[0]]);
formatter.display();
expect(logStub.callCount).to.equal(1);
expect(logStub.firstCall.args[0]).to.contain('No local or remote changes found.');
});
});
});