Skip to content

Users should not have to call .run() #1

@indexzero

Description

@indexzero

I think there is a small disconnect with how cli-easy works. Here's a sample from cli-easy-uname-test.js:

CLIEasy.describe('uname test')
       .use('uname')
       .discuss('calling without arguments')
         .run()
         .expect('should return Linux', 'Linux\n')
       .undiscuss()
       .discuss('calling with -p')
         .arg('-p')
         .run()
         .expect('should return current arch type', /x86_64/)
       .undiscuss()
       .discuss('calling with -r')
         .arg('-r')
         .run()
         .expect('should return kernel version', function(version) {
           var re = /^(\d+)\.(\d+)\.(\d+)\-(\d+)-([^\d]+)\n$/,
               match = version.match(re);
           if (match === null) return false;
           if (parseInt(match[1]) < 2) return false;
           return true;
         })
       .undiscuss()
       .discuss('calling with wrong arguments')
         .arg('-wrong-arg')
         .run('-another-wrong-arg')
         .expect('should exit with code = 1', null, 1)
         .expect('should write to stderr', null, /invalid option/)
       .undiscuss()
       .export(module);

I think this usage should be:

CLIEasy.describe('uname test')
       .use('uname')
       .discuss('calling without arguments')
         .expect('should return Linux', 'Linux\n')
       .undiscuss()
       .discuss('calling with -p')
         .arg('-p')
         .expect('should return current arch type', /x86_64/)
       .undiscuss()
       .discuss('calling with -r')
         .arg('-r')
         .expect('should return kernel version', function(version) {
           var re = /^(\d+)\.(\d+)\.(\d+)\-(\d+)-([^\d]+)\n$/,
               match = version.match(re);
           if (match === null) return false;
           if (parseInt(match[1]) < 2) return false;
           return true;
         })
       .undiscuss()
       .discuss('calling with wrong arguments')
         .arg('-wrong-arg')
         .arg('-another-wrong-arg')
         .expect('should exit with code = 1', null, 1)
         .expect('should write to stderr', null, /invalid option/)
       .undiscuss()
       .export(module);

Notice how I have removed all references to .run(). This is how api-easy works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions