taqueria icon indicating copy to clipboard operation
taqueria copied to clipboard

🚧 Dev ➾ Determine why yargs is not returning what's expected

Open mweichert opened this issue 2 years ago β€’ 2 comments

πŸ”— Epic|Feature Link

No response

πŸš₯ Definition of Done

  • [ ] 🎯 Planning and Design
  • [ ] 🏎️ Dev Implementation Complete
  • [ ] ♾️ PR Merged
  • [ ] πŸ† Product Acceptance

🧰 Work Description

In the CLI, we parse arguments from the CLI twice.

  • In our first run, we configure a yargs instance that is aware of all global options and tasks. We then parse against this yargs configuration to determine whether a global task was involved. If so, we execute that task and end the process.
  • In our second run, we have determined that a global task isn't to be executed. The ephemeral state is loaded so that we can configure a new yargs instance that is aware of all plugin provided tasks. We then parse against this yargs configuration to determine whether a plugin-provided task was requested.

However, there was a problem found during the internal-tasks-refactor work (#1613 ) in the second run of parsing.

Yargs is used to parse CLI arguments into commands, positional arguments, and option flags.

After yargs parses the CLI arguments, an object representing all options is returned. The command (or in Taqueria terminology, the "task") being invoked is stored in the '_' property. If you were to execute the 'generate types' task, then ')' would be set to ["generate", "types"].

In the first pass of parsing arguments, the '' property is set to as what we would expect: ["generate", "types"] In the second pass of parsing, the '' property is truncated for some reason: ["generate"]

Note, this is also present in main, and seems to have existed for a while, but only manifested in the internal-tasks-refactor work. The reason being is that the logic of the tasks refactor branch utilizes the '_' property to determine what task is being invoked. In main, we utilize yargs command handlers, which fork execution outside of the main execution pipeline.

To get around this at the moment, we just copy the '_' property from the initial pass of parsing arguments to the object resulting from the second pass of parsing. See here: https://github.com/ecadlabs/taqueria/blob/refactor-internal-tasks/cli.ts#L1125

βœ… To Do

  • [ ] Determine why the second call to parseArgs returns an object with the '_' array truncated
  • [ ] Apply a better solution

βš–οΈ Acceptance Criteria

We should know why parsing using yargs behaves this way, and remove any hacks that force things to work.

πŸ”­ Scope

Forking yargs.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

mweichert avatar Dec 10 '22 20:12 mweichert

What is the status of this?

egarson avatar Jan 04 '23 20:01 egarson

This is an exisiting issue, but its mitigated by the hack implemented above. For that reason, I'll consider this low priority.

mweichert avatar May 15 '23 21:05 mweichert