Skip to content

Commit

Permalink
Drop cargo-generate support (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
yozhgoor authored Oct 10, 2024
1 parent 3246197 commit ef846b8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 253 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ jobs:
name: build-${{ matrix.os }}
path: target/release/cargo-temp.exe

- name: Build release all-features (${{ matrix.os }})
run: cargo build --release --all-features

- if: matrix.os == 'ubuntu-latest'
run: strip target/release/cargo-temp

- uses: actions/upload-artifact@v3
if: matrix.os != 'windows-latest'
with:
name: build-${{ matrix.os }}-all-features
path: target/release/cargo-temp

- uses: actions/upload-artifact@v3
if: matrix.os == 'windows-latest'
with:
name: build-${{ matrix.os }}-all-features
path: target/release/cargo-temp.exe

release:
needs: [ build ]
runs-on: ubuntu-latest
Expand All @@ -72,36 +54,18 @@ jobs:
path: build-ubuntu-latest
- run: mv build-ubuntu-latest/cargo-temp build-ubuntu-latest/cargo-temp-${{ steps.get_version.outputs.VERSION }}-linux-x86_64

- uses: actions/download-artifact@v3
with:
name: build-ubuntu-latest-all-features
path: build-ubuntu-latest-all-features
- run: mv build-ubuntu-latest-all-features/cargo-temp build-ubuntu-latest/cargo-temp-all-features-${{ steps.get_version.outputs.VERSION }}-linux-x86_64

- uses: actions/download-artifact@v3
with:
name: build-windows-latest
path: build-windows-latest
- run: mv build-windows-latest/cargo-temp.exe build-windows-latest/cargo-temp-${{ steps.get_version.outputs.VERSION }}-windows-x86_64.exe

- uses: actions/download-artifact@v3
with:
name: build-windows-latest-all-features
path: build-windows-latest-all-features
- run: mv build-windows-latest-all-features/cargo-temp.exe build-windows-latest/cargo-temp-all-features-${{ steps.get_version.outputs.VERSION }}-windows-x86_64.exe

- uses: actions/download-artifact@v3
with:
name: build-macos-latest
path: build-macos-latest
- run: mv build-macos-latest/cargo-temp build-macos-latest/cargo-temp-${{ steps.get_version.outputs.VERSION }}-macos-x86_64

- uses: actions/download-artifact@v3
with:
name: build-macos-latest-all-features
path: build-macos-latest-all-features
- run: mv build-macos-latest-all-features/cargo-temp build-macos-latest/cargo-temp-all-features-${{ steps.get_version.outputs.VERSION }}-macos-x86_64

- name: Release
uses: softprops/action-gh-release@v1
env:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ jobs:
- name: rustup update
run: rustup update

- name: cargo check
run: cargo check

- name: cargo build
run: cargo build --all-features
run: cargo build

- name: cargo test
run: cargo test --all-features
run: cargo test

- name: rustfmt
if: github.event_name == 'pull_request' && matrix.lint
run: cargo fmt --all -- --check

- name: clippy
if: github.event_name == 'pull_request' && matrix.lint
run: cargo clippy --workspace --all-features --tests -- -D warnings
run: cargo clippy --tests -- -D warnings
8 changes: 4 additions & 4 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ jobs:
run: rustup update

- name: cargo check
run: cargo check --all-features
run: cargo check

- name: cargo build
run: cargo build --all-features
run: cargo build

- name: cargo test
run: cargo test --all-features
run: cargo test

- name: cargo fmt
run: cargo fmt --all --check

- name: cargo clippy
run: cargo clippy --tests --all-features -- -D warnings
run: cargo clippy --tests -- -D warnings

- name: install cargo-outdated
run: cargo install cargo-outdated
Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ keywords = ["cargo", "temporary", "project", "cli", "dependencies"]
categories = ["development-tools::cargo-plugins"]
include = ["src/**/*.rs", "README.md", "LICENSE.Apache-2.0", "LICENSE.MIT"]

[features]
generate = ["cargo-generate"]

[dependencies]
anyhow = "1"
cargo-generate = { version = "0.22", optional = true }
Expand Down
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ Requires Rust 1.51.
cargo install cargo-temp
```

If you want to use the `generate` feature, Rust 1.61 is required.

```
cargo install --all-features cargo-temp
```

Or

```
cargo install --features generate cargo-temp
```

## Usage

Create a new temporary project:
Expand Down Expand Up @@ -262,24 +250,6 @@ cargo-temp --name project
This name will be used as the suffix of the temporary project directory, like `tmp-wXyZ-project`.
If you decide to preserve the project, the directory will be renamed to match the project's name.

### Generate

Generate a temporary project from a template using [`cargo-generate`][cargo-generate]
(current used version is v0.16)

For example, to create a temporary project using [this template][cargo-generate-example-template]:

```
cargo temp generate --git https://github.com/ashleygwilliams/wasm-pack-template
```

Almost all the features of the [`cargo-generate`][cargo-generate] CLI are provided as it,
expections are:

* `--init` - This flag is used by cargo-temp to init the template as the temporary directory.
* `--destination` - Since we already use `--init`, this feature cannot be used with cargo-temp.
* `--allow-commands` - Needs further investigation to avoid conflicts with cargo-temp's subprocesses.

## Settings

The config file is located at `{CONFIG_DIR}/cargo-temp/config.toml`.
Expand Down Expand Up @@ -465,8 +435,6 @@ foreground = true
[demo]: t-rec.gif
[comparison]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#comparison-requirements
[criterion]: https://docs.rs/criterion/latest/criterion
[cargo-generate]: https://github.com/cargo-generate/cargo-generate
[cargo-generate-example-template]: https://github.com/ashleygwilliams/wasm-pack-template
[xdg]: https://docs.rs/xdg/latest/xdg/
[knownfolder]: https://docs.rs/dirs-2/latest/dirs_2/
[ssh-issue]: https://github.com/rust-lang/cargo/issues/1851
Expand Down
119 changes: 0 additions & 119 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,123 +50,4 @@ pub struct Cli {
/// If the argument doesn't match any of the options, the default is the latest edition
#[arg(long, short = 'e')]
pub edition: Option<u32>,

#[cfg(feature = "generate")]
#[command(subcommand)]
pub subcommand: Option<generate::Subcommand>,
}

#[cfg(feature = "generate")]
pub mod generate {
use anyhow::Result;
use std::path::{Path, PathBuf};

#[derive(Clone, Debug, clap::Subcommand)]
pub enum Subcommand {
/// Generate a temporary project from a template using `cargo-generate`.
Generate(Args),
}

#[derive(Clone, Debug, clap::Args)]
pub struct Args {
#[command(flatten)]
pub template_path: cargo_generate::TemplatePath,
/// List defined favorite templates from the config
#[arg(
long,
conflicts_with_all(&[
"git", "path", "subfolder", "branch",
"name",
"force",
"silent",
"vcs",
"lib",
"bin",
"define",
"template_values_file",
"ssh_identity",
"test",
])
)]
pub list_favorites: bool,
/// Directory to create / project name; if the name isn't in kebab-case, it will be converted
/// to kebab-case unless `--force` is given.
#[arg(long, short)]
pub name: Option<String>,
/// Don't convert the project name to kebab-case before creating the directory.
/// Note that cargo generate won't overwrite an existing directory, even if `--force` is given.
#[arg(long, short)]
pub force: bool,
/// Enables more verbose output.
#[arg(long, short)]
pub verbose: bool,
/// Pass template values through a file
/// Values should be in the format `key=value`, one per line
#[arg(long)]
pub template_values_file: Option<String>,
/// If silent mode is set all variables will be
/// extracted from the template_values_file.
/// If a value is missing the project generation will fail
#[arg(long, short, requires("name"))]
pub silent: bool,
/// Use specific configuration file. Defaults to $CARGO_HOME/cargo-generate or $HOME/.cargo/cargo-generate
#[arg(short, long)]
pub config: Option<PathBuf>,
/// Specify the VCS used to initialize the generated template.
#[arg(long)]
pub vcs: Option<cargo_generate::Vcs>,
/// Populates template variable `crate_type` with value `"lib"`
#[arg(long, conflicts_with = "bin")]
pub lib: bool,
/// Populates a template variable `crate_type` with value `"bin"`
#[arg(long, conflicts_with = "lib")]
pub bin: bool,
/// Use a different ssh identity
#[arg(short = 'i', long = "identity")]
pub ssh_identity: Option<PathBuf>,
/// Define a value for use during template expansion
#[arg(long, short, number_of_values = 1)]
pub define: Vec<String>,
/// Use a different gitconfig file, if omitted the usual $HOME/.gitconfig will be used.
#[arg(long = "gitconfig")]
pub gitconfig: Option<PathBuf>,
/// Will enforce a fresh git init on the generated project
#[arg(long)]
pub force_git_init: bool,
/// Allow the template to overwrite existing files in the destination.
#[arg(short, long)]
pub overwrite: bool,
/// Skip downloading git submodules (if there are any)
#[arg(short, long)]
pub skip_submodules: bool,
}

impl Args {
pub fn generate(self, destination: &Path) -> Result<PathBuf> {
cargo_generate::generate(cargo_generate::GenerateArgs {
template_path: self.template_path,
list_favorites: self.list_favorites,
name: self.name,
force: self.force,
verbose: self.verbose,
template_values_file: self.template_values_file,
silent: self.silent,
config: self.config,
vcs: self.vcs,
lib: self.lib,
bin: self.bin,
ssh_identity: self.ssh_identity,
gitconfig: self.gitconfig,
define: self.define,
force_git_init: self.force_git_init,
overwrite: self.overwrite,
skip_submodules: self.skip_submodules,
// Not available for the users.
destination: Some(destination.to_path_buf()),
init: false,
allow_commands: false,
other_args: None,
})
}
}
}
Loading

0 comments on commit ef846b8

Please sign in to comment.