Skip to content

Refactor cli.js and folder structure to fit yargs commandDir() function #13

Closed
@aichbauer

Description

@aichbauer

Right now we use the cli.js with argv options that gets parsed and then we have a if-else construct.

Like:

const argv = yargs
  .alias('o1', 'option1')
  .description('o1', 'description for o1')
  .alias('o2', 'option2')
  .description('o2', 'description for o2')
  .help()
  .argv;

if (argv.option1) {
  // do something
} else if (argv.option2) {
  // do something else
} else {
  // do default stuff
}

But maybe it would be more readable if we use commands instead? For example with the commandDir() from yargs.

So the cli.js is really only the cli. Because the recoverTasks() function is also part of the cli but is not named as one.

Like:

yargs
  .commandDir('cmds')
  .demandCommand()
  .help()
  .argv;

and a dir like:

.
|
+-- cmds
|   |
|   +-- default.js
|   |
|   +-- recover.js
|
+-- tasks
|   +-- recover-tasks
|   |
|   +-- default-tasks
|
+-- helpers
|
+-- cli.js

Because i think a --flag should more used to be a boolean. But right now --recover can take a string as argument. And after this refactoring this would be sgr [command] <argument> => sgr recover backup. This would be a breaking change since the --recover flag would change to the recover command that can take an argument. The default command would be the same sgr or semantic-git-release.

@JPeer264 what do you think about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions