Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-M0 committed Nov 29, 2023
2 parents 743c722 + 1689637 commit 6ffd144
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
ra = "run --bin cargo-alias -- alias"
ru = "run --bin cargo-unalias -- unalias"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.2.2

### Bugs fixed

- Panic when `$CARGO_HOME/config.toml` doesn't exist

## v0.2.1

### Bugs fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-alias"
version = "0.2.1"
version = "0.2.2"
authors = ["James Morris <[email protected]>"]
edition = "2018"
description = "Easily view, create, and delete cargo aliases"
Expand Down
10 changes: 2 additions & 8 deletions src/bin/cargo-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::bail;
use clap::Parser;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use toml_edit::{value, Document, Item, Value};

#[derive(Parser)]
Expand All @@ -20,21 +20,15 @@ struct Opt {

fn main() -> anyhow::Result<()> {
let user_config = PathBuf::from(env::var("CARGO_HOME")?).join("config.toml");
let current_config = env::current_dir()?;
let cargo_config = Path::new(".cargo").join("config.toml");

let Cargo::Alias(opt) = Cargo::parse();

// for ans in current_config.ancestors() {
// println!("{:?}", ans.join(&cargo_config));
// }

let mut config: Document = match fs::read_to_string(&user_config) {
Ok(string) => string.parse()?,
Err(_) => Document::new(),
};

if config["alias"].as_table().is_none() {
if !config.contains_table("alias") {
config["alias"] = toml_edit::table();
}

Expand Down
7 changes: 5 additions & 2 deletions src/bin/cargo-unalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ fn main() -> anyhow::Result<()> {
let cargo_home_config = PathBuf::from(env::var("CARGO_HOME")?).join("config.toml");

let mut config: Document = fs::read_to_string(&cargo_home_config)?.parse()?;
config["alias"].as_table_mut().unwrap().remove(&opt.alias);
fs::write(cargo_home_config, config.to_string())?;

if config.contains_table("alias") {
config["alias"].as_table_mut().unwrap().remove(&opt.alias);
fs::write(cargo_home_config, config.to_string())?;
}

Ok(())
}

0 comments on commit 6ffd144

Please sign in to comment.