Skip to content

Commit

Permalink
Merge pull request #1278 from axodotdev/opt_in_init_flag
Browse files Browse the repository at this point in the history
feat: guard new config format behind hidden flag
  • Loading branch information
mistydemeo authored Aug 6, 2024
2 parents 8c2f5f9 + 0874ea5 commit 12066a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
6 changes: 6 additions & 0 deletions cargo-dist/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ pub struct InitArgs {
/// `cargo dist init` will persist the values you pass to that location.
#[clap(long, value_delimiter(','))]
pub hosting: Vec<HostingStyle>,
/// Opts into the new configuration format
#[clap(long, hide = true)]
pub opt_in_migrate: bool,
}

/// Which style(s) of configuration to generate
Expand Down Expand Up @@ -377,6 +380,9 @@ pub struct UpdateArgs {
/// `cargo dist init` will persist the values you pass to that location.
#[clap(long, value_delimiter(','))]
pub hosting: Vec<HostingStyle>,
/// Opts into the new configuration format
#[clap(long, hide = true)]
pub opt_in_migrate: bool,
}

/// A style of CI to generate
Expand Down
51 changes: 28 additions & 23 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct InitArgs {
pub with_json_config: Option<Utf8PathBuf>,
/// Hosts to enable
pub host: Vec<HostingStyle>,
/// Whether to migrate to the new config format
pub migrate_to_new_config: bool,
}

/// Input for --with-json-config
Expand Down Expand Up @@ -104,34 +106,37 @@ pub fn do_init(cfg: &Config, args: &InitArgs) -> DistResult<()> {
// If this is a Cargo.toml, offer to either write their config to
// a dist-workspace.toml, or migrate existing config there
let mut is_migrating = false;
let mut newly_initted_generic = false;
// Users who haven't initted yet should be opted into the
// new config format by default.
let desired_workspace_kind = if root_workspace.kind == WorkspaceKind::Rust && !initted {
WorkspaceKind::Generic
// Already-initted users should be asked whether to migrate.
} else if root_workspace.kind == WorkspaceKind::Rust {
let prompt = r#"Would you like to opt in to the new configuration format?
let desired_workspace_kind =
if root_workspace.kind == WorkspaceKind::Rust && !initted && args.migrate_to_new_config {
newly_initted_generic = true;
WorkspaceKind::Generic
// Already-initted users should be asked whether to migrate.
} else if root_workspace.kind == WorkspaceKind::Rust && args.migrate_to_new_config {
let prompt = r#"Would you like to opt in to the new configuration format?
Future versions of cargo-dist will feature major changes to the
configuration format, including a new cargo-dist-specific configuration file."#;
let res = if args.yes {
// We want to avoid --yes pulling it in at this point.
false
} else {
dialoguer::Confirm::with_theme(&theme())
.with_prompt(prompt)
.default(false)
.interact()?
};
let res = if args.yes {
// We want to avoid --yes pulling it in at this point.
false
} else {
dialoguer::Confirm::with_theme(&theme())
.with_prompt(prompt)
.default(args.migrate_to_new_config)
.interact()?
};

if res {
is_migrating = true;
WorkspaceKind::Generic
if res {
is_migrating = true;
WorkspaceKind::Generic
} else {
root_workspace.kind
}
} else {
root_workspace.kind
}
} else {
root_workspace.kind
};
};

let multi_meta = if let Some(json_path) = &args.with_json_config {
// json update path, read from a file and apply all requested updates verbatim
Expand All @@ -154,7 +159,7 @@ pub fn do_init(cfg: &Config, args: &InitArgs) -> DistResult<()> {
// If we're migrating, the configuration will be missing the
// generic workspace specification, and will have some
// extraneous cargo-specific stuff that we don't want.
let mut workspace_toml = if is_migrating || !initted {
let mut workspace_toml = if is_migrating || newly_initted_generic {
// Always generate a new workspace here for the !initted case
let mut new_workspace = toml_edit::DocumentMut::new();

Expand Down Expand Up @@ -190,7 +195,7 @@ pub fn do_init(cfg: &Config, args: &InitArgs) -> DistResult<()> {
let destination;
// If we're migrating, *or* if we're doing a first-time init,
// calculate the filename to write to
if is_migrating || !initted {
if is_migrating || newly_initted_generic {
filename = match desired_workspace_kind {
WorkspaceKind::Rust => "Cargo.toml",
WorkspaceKind::Generic | WorkspaceKind::Javascript => "dist-workspace.toml",
Expand Down
1 change: 1 addition & 0 deletions cargo-dist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ fn cmd_init(cli: &Cli, args: &InitArgs) -> Result<(), miette::Report> {
no_generate: args.skip_generate,
with_json_config: args.with_json_config.clone(),
host: args.hosting.iter().map(|host| host.to_lib()).collect(),
migrate_to_new_config: args.opt_in_migrate,
};
do_init(&config, &args)?;
Ok(())
Expand Down

0 comments on commit 12066a0

Please sign in to comment.