Skip to content

Commit

Permalink
feat: Add option to not shorten long names in clasp list (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
elderfd authored Dec 14, 2020
1 parent 0e1bdc0 commit f8438af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import {ERROR, LOG} from '../messages';
import {URL} from '../urls';
import {checkIfOnlineOrDie, ellipsize, spinner, stopSpinner} from '../utils';

interface CommandOption {
readonly noShorten: boolean;
}

/**
* Lists a user's Apps Script projects using Google Drive.
* @param options.noShorten {boolean}
*/
export default async (): Promise<void> => {
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();

Expand All @@ -32,7 +37,7 @@ export default async (): Promise<void> => {

if (files.length > 0) {
for (const file of files) {
console.log(`${ellipsize(file.name!, 20)} - ${URL.SCRIPT(file.id ?? '')}`);
console.log(`${!options.noShorten ? ellipsize(file.name!, 20) : file.name} - ${URL.SCRIPT(file.id ?? '')}`);
}
} else {
console.log(LOG.FINDING_SCRIPTS_DNE);
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ commander.command('versions').description('List versions of a script').action(ve
* @example list # helloworld1 - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
* @todo Add --all flag to list all projects.
*/
commander.command('list').description('List App Scripts projects').action(list);
commander
.command('list')
.description('List App Scripts projects')
.option('--noShorten', 'Do not shorten long names', false)
.action(list);

/**
* Prints StackDriver logs.
Expand Down
7 changes: 7 additions & 0 deletions test/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ describe('Test clasp list function', () => {
expect(result.stderr).to.equal('');
expect(result.status).to.equal(0);
});
it('does not shorten project names when indicated not to', () => {
const result = spawnSync(CLASP, ['list', '--noShorten'], {encoding: 'utf8'});
expect(result.stdout).to.contain('https://script.google.com/d/');
expect(result.stdout).to.not.contain('…');
expect(result.stderr).to.equal('');
expect(result.status).to.equal(0);
});
after(cleanup);
});

0 comments on commit f8438af

Please sign in to comment.