Skip to content

Commit 5711936

Browse files
committed
run command & new log macros
1 parent da8848c commit 5711936

File tree

13 files changed

+141
-77
lines changed

13 files changed

+141
-77
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ description = "discord version manager for linux"
44
homepage = "https://github.com/diced/dvm"
55
repository = "https://github.com/diced/dvm.git"
66
license = "MIT"
7-
version = "1.1.6"
7+
version = "1.1.7"
88
authors = ["diced <[email protected]>"]
9-
edition = "2018"
9+
edition = "2021"
1010

1111
[[bin]]
1212
name = "dvm"
1313

14-
15-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
16-
1714
[dependencies]
1815
tokio = { version = "1.6.0", features = ["full"] }
1916
reqwest = { version = "0.11.3", features = ["json", "native-tls", "blocking"], default-features = false }

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Allowing you to manage all of your discord versions. This was made as I was impa
44

55
# Usage
66
```
7-
dvm 0.1.1
7+
dvm 1.1.4
88
99
USAGE:
1010
dvm <SUBCOMMAND>
@@ -14,11 +14,13 @@ FLAGS:
1414
-V, --version Prints version information
1515
1616
SUBCOMMANDS:
17-
help Prints this message or the help of the given subcommand(s)
18-
install install the latest <type> of discord
19-
remove remove the installed <type> of discord
20-
show show all installed versions
21-
update update to the latest <type> of discord
17+
completions get shell completions
18+
help Prints this message or the help of the given subcommand(s)
19+
install install the latest <type> of discord
20+
remove remove the installed <type> of discord
21+
run run discord with specific options
22+
show show all installed versions
23+
update update to the latest <type> of discord
2224
```
2325

2426
# Installing

src/cli/install.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub async fn install(release_type: Type, verbose: bool) -> Res<()> {
77
let user = env::var("USER")?;
88
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
99
if verbose {
10-
info("created .dvm dir")
10+
info!("created .dvm dir")
1111
}
1212

1313
let pascal_pkg = match release_type {
@@ -20,12 +20,11 @@ pub async fn install(release_type: Type, verbose: bool) -> Res<()> {
2020
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
2121

2222
if exists {
23-
error(format!("{} is already installed", release_type));
24-
std::process::exit(1);
23+
error!("{} is already installed", release_type);
2524
}
2625

2726
let (latest, _) = install_version(false, release_type.clone(), verbose, user).await?;
2827

29-
success(format!("installed {}:{}", release_type, latest));
28+
success!("installed {}:{}", release_type, latest);
3029
Ok(())
3130
}

src/cli/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ mod install;
22
mod remove;
33
mod show;
44
mod update;
5+
mod run;
56

6-
pub use {install::install, remove::remove, show::show, update::update};
7+
pub use {install::install, remove::remove, show::show, update::update, run::run};

src/cli/remove.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,32 @@ pub async fn remove(release_type: Type, verbose: bool) -> Res<()> {
2323

2424
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
2525
if verbose {
26-
info("checking if installation exists")
26+
info!("checking if installation exists")
2727
}
2828

2929
if !exists {
30-
error(format!("{} not installed", release_type));
31-
std::process::exit(1);
30+
error!("{} not installed", release_type);
3231
}
3332

3433
let version = fs::read_to_string(format!("/home/{}/.dvm/{}/version", user, pascal_pkg))
3534
.expect("could not read version file: malformed installation detected");
3635
if verbose {
37-
info("reading version file")
36+
info!("reading version file")
3837
}
3938

40-
info(format!("removing version {}:{}", release_type, version));
39+
info!("removing version {}:{}", release_type, version);
4140

4241
// remove all {release type} associated files
4342
fs::remove_dir_all(format!("/home/{}/.dvm/{}", user, pascal_pkg))
4443
.expect("error when removing data dirs");
4544
if verbose {
46-
info("removed data dirs")
45+
info!("removed data dirs")
4746
}
4847

4948
fs::remove_file(format!("/home/{}/.dvm/bin/{}", user, pkg_name))
5049
.expect("error when removing bin file");
5150
if verbose {
52-
info("removed bin file")
51+
info!("removed bin file")
5352
}
5453

5554
fs::remove_file(format!(
@@ -58,7 +57,7 @@ pub async fn remove(release_type: Type, verbose: bool) -> Res<()> {
5857
))
5958
.expect("error when removing desktop file");
6059
if verbose {
61-
info("removed desktop file")
60+
info!("removed desktop file")
6261
}
6362

6463
fs::remove_file(format!(
@@ -67,9 +66,9 @@ pub async fn remove(release_type: Type, verbose: bool) -> Res<()> {
6766
))
6867
.expect("error when removing icon");
6968
if verbose {
70-
info("removed icon")
69+
info!("removed icon")
7170
}
7271

73-
success(format!("removed version {}:{}", release_type, version));
72+
success!("removed version {}:{}", release_type, version);
7473
Ok(())
7574
}

src/cli/run.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::{env, fs, path::Path};
2+
3+
use tokio::process::Command;
4+
5+
use crate::{Res, error, info, r#type::Type};
6+
7+
pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()> {
8+
// create user var & create .dvm dirs
9+
let user = env::var("USER")?;
10+
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
11+
12+
// create user var & create .dvm dirs
13+
let user = env::var("USER")?;
14+
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
15+
if verbose {
16+
info!("created .dvm dir")
17+
}
18+
19+
let pascal_pkg = match release_type {
20+
Type::STABLE => "Discord",
21+
Type::PTB => "DiscordPTB",
22+
Type::CANARY => "DiscordCanary",
23+
Type::DEVELOPMENT => "DiscordDevelopment",
24+
};
25+
26+
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
27+
28+
if !exists {
29+
error!("{} is not installed", release_type);
30+
}
31+
32+
Command::new(format!("/home/{}/.dvm/{}/{}", user, pascal_pkg, pascal_pkg))
33+
.args(&args)
34+
.spawn()?
35+
.wait_with_output().await?;
36+
37+
Ok(())
38+
}

src/cli/update.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn update(release_type: Type, verbose: bool) -> Res<()> {
1111
let user = env::var("USER")?;
1212
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
1313
if verbose {
14-
info("created .dvm dir")
14+
info!("created .dvm dir")
1515
}
1616

1717
let pascal_pkg = match release_type {
@@ -24,16 +24,15 @@ pub async fn update(release_type: Type, verbose: bool) -> Res<()> {
2424
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
2525

2626
if !exists {
27-
error(format!("{} is not installed", release_type));
28-
std::process::exit(1);
27+
error!("{} is not installed", release_type);
2928
}
3029

3130
let (latest, version) = install_version(true, release_type.clone(), verbose, user).await?;
3231

33-
success(format!(
32+
success!(
3433
"updated {}:{} -> {}:{}",
3534
release_type, version, release_type, latest
36-
));
35+
);
3736

3837
Ok(())
3938
}

src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub const SHOW_DESC: &str = "show all installed versions";
99
pub const SHOW_ALIASES: &[&str] = &["s", "installed", "all", "a", "versions", "types"];
1010
pub const COMP_DESC: &str = "get shell completions";
1111
pub const COMP_ALIASES: &[&str] = &["c", "comp"];
12+
pub const RUN_DESC: &str = "run discord with specific options";
13+
pub const RUN_ALIASES: &[&str] = &["r", "start", "s"];
1214

1315
pub const POSSIBLE_SHELLS: &[&str] = &[
1416
"bash", "b",

src/completions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ pub fn give_completions(shell: &str) {
1212
"powershell" | "pwsh" | "ps" | "p" => return_bash(),
1313
"zsh" | "z" => return_bash(),
1414
_ => {
15-
error(format!("shell \"{}\" is not supported", shell));
16-
std::process::exit(1);
15+
error!("shell \"{}\" is not supported", shell);
1716
}
1817
};
1918
}

0 commit comments

Comments
 (0)