Skip to content

ng generate does not accept schematic options of type "object" #22173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 15 tasks
jesusreal opened this issue Nov 16, 2021 · 2 comments · Fixed by #22779
Closed
1 of 15 tasks

ng generate does not accept schematic options of type "object" #22173

jesusreal opened this issue Nov 16, 2021 · 2 comments · Fixed by #22779

Comments

@jesusreal
Copy link

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

No

Description

Given a custom schematic called my-test-schematic with its schema defining an object type, as for example the localize property below:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "MyTestSchematicsSchema",
  "title": "My test schematics Schema",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "localize": {
      "description": "Provide locale, localeFile to add it as an additional output of the application.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "locale": {
          "type": "string",
          "title": "Single locale to use (besides the default)"
        },
        "localeFile": {
          "type": "string",
          "title": "Single locale file matching the given locale"
        }
      }
    }
  }
}

Running such schematic with ng generate command

ng g ./dist/libs/schematics/collection.json:my-test-schematic --localize.locale=de

Produces the following error:

Unknown option: '--localize.locale'

Running the schematic with schematics command

schematics ./dist/libs/schematics/collection.json:my-test-schematic --localize.locale=de

The option is passed to the schematic:

My test schematic: {"localize":{"locale":"de"}}

I would expect ng generate to support schematic options of type object, the same way schematics does. Here is where extraction happens for ng generate, and here for schematics.

🔬 Minimal Reproduction

I created a public repository here that allows to reproduce the issue. All the relevant information is in the readme file.

🔥 Exception or Error

When running the schematic with ng generate command




Unknown option: '--localize.locale'

When running the schematic with schematics command, the option is properly passed to the schematic

🌍 Your Environment




Angular CLI: 12.1.3
Node: 14.17.6
Package Manager: npm 6.14.15
OS: darwin x64

Angular: 
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1201.3 (cli-only)
@angular-devkit/build-angular   
@angular-devkit/core            12.2.13
@angular-devkit/schematics      12.2.13
@angular/cli                    12.1.3 (cli-only)
@schematics/angular             12.1.3 (cli-only)
rxjs                            6.6.7
typescript                      4.3.5

Anything else relevant?
No

@alan-agius4
Copy link
Collaborator

This is expected, the command line parser of the Angular CLI doesn’t expand properties with dots into objects. I am actually surprised that this work in the schematics CLI.

In a future major version we will be looking into using a common parser for all of the CLIs so that the parsing of arguments is consistent across the board. That said, it’s not very likely that the object expansion would be something that we’d want to allow.

@ngbot ngbot bot modified the milestone: needsTriage Nov 22, 2021
@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely type: bug/fix labels Nov 22, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Nov 22, 2021
dgp1130 pushed a commit that referenced this issue Mar 2, 2022
…arser

BREAKING CHANGE: camel case arguments are no longer allowed.

Closes #13544, closes #12150, closes #22173
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants