Skip to content
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

feat(json-init): add a --with-json-config=path/to/config.json flag for passing json to init #279

Merged
merged 6 commits into from
Jul 20, 2023

Conversation

Gankra
Copy link
Member

@Gankra Gankra commented Jul 18, 2023

This exists for hosted services that want to edit the toml mechanically.
The format is basically the json equivalent of [workspace.metadata.dist],
wrapped in a workspace field:

{
    "workspace": {
        "cargo-dist-version": "0.1.0-prerelease.2",
        "ci": ["github"],
        "installers": ["shell", "powershell"],
        "targets": ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"]
    }
}

The given values will complete overwrite the [workspace.metadata.dist] section,
so if any fields are omitted they will be deleted from the Cargo.toml.

All the interactive logic that init supports will be ignored in this mode
(this is NOT equivalent to --yes, which runs the logic and just accepts every prompt).

generate-ci will be run afterwards as usual (disable with --no-generate-ci as usual).

fixes #278

@Gankra
Copy link
Member Author

Gankra commented Jul 18, 2023

I think the fundamental question here is whether the input should overwrite the Cargo.toml completely, or if it should be a set of updates overlayed onto the current value.

Specifically this affects fields that are omitted from the json -- is that "delete the key" or "preserve the old value"?

@Gankra
Copy link
Member Author

Gankra commented Jul 19, 2023

On config handling rework (stuff now generally works a bit more like oranda config):

  • I use the "pattern match on the entire config to force people to update key functions" trick

    • A few functions explicitly ignore the fields with field: _ which is fine, all that matters is that when a field gets added you need to go to that function and take the moment to think if that field can be ignored too
  • All fields are Options now

    • Previously we let Vecs be non-optional in more places which was a bit confusing about how they get merged
    • We do extend exactly one Vec if both workspace and package defines it -- includes
    • Theoretically this makes sense so you can have files that are included in everything and then packages still have the ability to add some stuff to it, but it's weird that it's inconsistent. It isn't an expressivity limitation, because if people don't want this behaviour they can just not use the global version at all.
  • In init if a field is None we will delete it from the Cargo.toml

    • For array fields we will also do it if the array is empty
    • Now that everything is an option I need to reconsider if that makes sense
  • In doing this I found a minor bug in how we handle npm-scope (fixed in third commit)

…r passing json to init

This exists for hosted services that want to edit the toml mechanically.
The format is basically the json equivalent of `[workspace.metadata.dist]`,
wrapped in a `workspace` field:

```json
{
    "workspace": {
        "cargo-dist-version": "0.1.0-prerelease.2",
        "ci": ["github"],
        "installers": ["shell", "powershell"],
        "targets": ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"]
    }
}
```

The given values will complete overwrite the `[workspace.metadata.dist]` section,
so if any fields are omitted they will be deleted from the Cargo.toml.

All the interactive logic that `init` supports will be ignored in this mode
(this is *NOT* equivalent to --yes, which runs the logic and just accepts every prompt).

generate-ci will be run afterwards as usual (disable with --no-generate-ci as usual).

fixes #278
and make it generalized to all packages to be future-proof
For whatever reason it was reading it from workspace_metadata, which is just wrong
(probably no one noticed, non-workspace config is rare with cargo-dist, and this settting
is pretty naturally universal).
@Gankra Gankra changed the title WIP: add a flag for passing json to init feat(json-init): add a --with-json-config=path/to/config.json flag fo… a8fbbb7 …r passing json to init Jul 19, 2023
@Gankra Gankra changed the title feat(json-init): add a --with-json-config=path/to/config.json flag fo… a8fbbb7 …r passing json to init feat(json-init): add a --with-json-config=path/to/config.json flag for passing json to init Jul 19, 2023
@Gankra
Copy link
Member Author

Gankra commented Jul 20, 2023

landing this to unblock some further cleanup work without making this pr spiral out of control

@Gankra Gankra merged commit cb8131b into main Jul 20, 2023
11 checks passed
@Gankra Gankra deleted the json-init branch July 20, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

json input for cargo dist init
1 participant