rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] command-line.json supports specifying custom remainder for commands and phases

Open chengcyber opened this issue 3 years ago • 2 comments

Summary

This PR proposes specifying custom remainder for commands and phases in "command-line.json"

Details

  • Add "remainders" property in "command-line.json"
  • Each item in "remainders" associates with commands or phases
  • The associated commands/phases can get the argument list after recognized portion.

How it was tested

modify "common/config/rush/command-line.json"

  "commands": [
    {
      "commandKind": "global",
      "name": "echo",
      "summary": "echo argv",
      "shellCommand": "echo $@"
    },

   // ...

   "remainders": [
     {
        "description": "rest arguments"
        "associatedCommands": ["echo"]
     }
   ]

Run node libraries/rush-lib/lib/start.js echo a b c, it prints

image

Run node libraries/rush-lib/lib/start.js echo -h, it prints

image

chengcyber avatar Nov 22 '22 05:11 chengcyber

What happens when a command/phase is associated with two remainders?

My inclination would be to treat the remainder as a singleton that can be associated with commands or phases, and just have a hardcoded description.

iclanton avatar Dec 06 '22 05:12 iclanton

What happens when a command/phase is associated with two remainders?

Yes. remainder should be a singleton. We should forbid (throw error) when declaring two remainders for the same command

My inclination would be to treat the remainder as a singleton that can be associated with commands or phases, and just have a hardcoded description.

Are you proposing something like the following?

common/config/rush/command-line.json

{
   "remainders": {  // a list of different remainders -> a object declares associated commands and/or phases
      // no description setting at all
      "associatedCommands": [ "FOO", "BAR" ]         // should be unique
      "associatedPhases": ["_phase:FOO", "_phase:BAR"]      //  should be unique
   }
}

If so, the only concern is there is no way to archive the use case as follow:

   "remainders": [
      {
         "associatedCommands": [ "FOO"]         
        "associatedPhases": ["_phase:FOO", "_phase:BAR"]    
      },
      {
         "associatedCommands": ["BAR" ]         
        "associatedPhases": ["_phase:BAR"]    
      }
   ]

custom remainder for _phase:FOO only for FOO command, but not for BAR command.

Maybe the use case is not a big deal (?)

chengcyber avatar Dec 07 '22 06:12 chengcyber