Skip to content

Commit 867f236

Browse files
authored
Merge pull request #7 from arduano/trunk
Updating dependencies to be able to compile again, plus various cleanups
2 parents 4e7d77c + 4d600a4 commit 867f236

File tree

17 files changed

+1463
-746
lines changed

17 files changed

+1463
-746
lines changed

Cargo.lock

Lines changed: 592 additions & 445 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "dvm"
33
description = "discord version manager for linux"
44
homepage = "https://github.com/diced/dvm"
55
repository = "https://github.com/diced/dvm.git"
6-
license = "MIT"
6+
license = "GPL-3"
77
version = "1.1.9"
88
authors = ["diced <pranaco2@gmail.com>"]
99
edition = "2021"
@@ -13,7 +13,11 @@ name = "dvm"
1313

1414
[dependencies]
1515
tokio = { version = "1.6.0", features = ["full"] }
16-
reqwest = { version = "0.11.3", features = ["json", "native-tls", "blocking"], default-features = false }
16+
reqwest = { version = "0.11.3", features = [
17+
"json",
18+
"native-tls",
19+
"blocking",
20+
], default-features = false }
1721
colored = "2.0.0"
18-
clap = "3.0.0-beta.2"
19-
clap_generate = "3.0.0-beta.2"
22+
clap = { version = "4.4.11", features = ["derive", "color"] }
23+
clap_complete = "4.4.4"

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

src/branch.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::fmt;
2+
3+
use clap::ValueEnum;
4+
5+
#[derive(Debug, Clone, Copy)]
6+
pub enum DiscordBranch {
7+
STABLE,
8+
PTB,
9+
CANARY,
10+
DEVELOPMENT,
11+
}
12+
13+
impl fmt::Display for DiscordBranch {
14+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15+
write!(f, "{}", self.to_possible_value().unwrap().get_name())
16+
}
17+
}
18+
19+
impl clap::ValueEnum for DiscordBranch {
20+
fn value_variants<'a>() -> &'a [Self] {
21+
&[
22+
DiscordBranch::STABLE,
23+
DiscordBranch::CANARY,
24+
DiscordBranch::PTB,
25+
DiscordBranch::DEVELOPMENT,
26+
]
27+
}
28+
29+
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
30+
match self {
31+
DiscordBranch::STABLE => Some(clap::builder::PossibleValue::new("stable")),
32+
DiscordBranch::CANARY => Some(clap::builder::PossibleValue::new("canary")),
33+
DiscordBranch::PTB => Some(clap::builder::PossibleValue::new("ptb")),
34+
DiscordBranch::DEVELOPMENT => Some(clap::builder::PossibleValue::new("development")),
35+
}
36+
}
37+
}

src/cli/install.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{ env, fs, path::Path};
1+
use std::{env, fs, path::Path};
22

3-
use crate::{error, info, r#type::Type, success, Res, util::install_version};
3+
use crate::{branch::DiscordBranch, error, info, success, util::install_version, Res};
44

5-
pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<()> {
5+
pub async fn install(release_type: DiscordBranch, verbose: bool, open_asar: bool) -> Res<()> {
66
// create user var & create .dvm dirs
77
let user = env::var("USER")?;
88
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
@@ -11,10 +11,10 @@ pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<
1111
}
1212

1313
let pascal_pkg = match release_type {
14-
Type::STABLE => "Discord",
15-
Type::PTB => "DiscordPTB",
16-
Type::CANARY => "DiscordCanary",
17-
Type::DEVELOPMENT => "DiscordDevelopment",
14+
DiscordBranch::STABLE => "Discord",
15+
DiscordBranch::PTB => "DiscordPTB",
16+
DiscordBranch::CANARY => "DiscordCanary",
17+
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
1818
};
1919

2020
let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();
@@ -31,10 +31,11 @@ pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<
3131
fs::rename(&asar_file, format!("{}.bak", &asar_file))?;
3232
info!("renamed app.asar to app.asar.bak (if discord doesn't work after this, rename it back)");
3333

34-
let res = reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
35-
.await?
36-
.bytes()
37-
.await?;
34+
let res =
35+
reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
36+
.await?
37+
.bytes()
38+
.await?;
3839

3940
fs::write(&asar_file, res)?;
4041

src/cli/install_openasar.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{env, fs, path::Path};
22

3-
use crate::{error, info, r#type::Type, success, Res};
3+
use crate::{branch::DiscordBranch, error, info, success, Res};
44

5-
pub async fn install_openasar(release_type: Type, verbose: bool) -> Res<()> {
5+
pub async fn install_openasar(release_type: DiscordBranch, verbose: bool) -> Res<()> {
66
// create user var & create .dvm dirs
77
let user = env::var("USER")?;
88
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
@@ -11,10 +11,10 @@ pub async fn install_openasar(release_type: Type, verbose: bool) -> Res<()> {
1111
}
1212

1313
let pascal_pkg = match release_type {
14-
Type::STABLE => "Discord",
15-
Type::PTB => "DiscordPTB",
16-
Type::CANARY => "DiscordCanary",
17-
Type::DEVELOPMENT => "DiscordDevelopment",
14+
DiscordBranch::STABLE => "Discord",
15+
DiscordBranch::PTB => "DiscordPTB",
16+
DiscordBranch::CANARY => "DiscordCanary",
17+
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
1818
};
1919

2020
let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();

src/cli/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
mod install;
22
mod install_openasar;
33
mod remove;
4+
mod run;
45
mod show;
56
mod update;
6-
mod run;
77

8-
pub use {install::install, install_openasar::install_openasar, remove::remove, show::show, update::update, run::run};
8+
pub use install::install;
9+
pub use install_openasar::install_openasar;
10+
pub use remove::remove;
11+
pub use run::run;
12+
pub use show::show;
13+
pub use update::update;

src/cli/remove.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use std::{env, fs, path::Path};
22

3-
use crate::{error, info, r#type::Type, success, Res};
3+
use crate::{branch::DiscordBranch, error, info, success, Res};
44

5-
pub async fn remove(release_type: Type, verbose: bool) -> Res<()> {
5+
pub async fn remove(release_type: DiscordBranch, verbose: bool) -> Res<()> {
66
// create user var & create .dvm dirs
77
let user = env::var("USER")?;
88
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
99

1010
let pascal_pkg = match release_type {
11-
Type::STABLE => "Discord",
12-
Type::PTB => "DiscordPTB",
13-
Type::CANARY => "DiscordCanary",
14-
Type::DEVELOPMENT => "DiscordDevelopment",
11+
DiscordBranch::STABLE => "Discord",
12+
DiscordBranch::PTB => "DiscordPTB",
13+
DiscordBranch::CANARY => "DiscordCanary",
14+
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
1515
};
1616

1717
let pkg_name = match release_type {
18-
Type::STABLE => "discord",
19-
Type::PTB => "discord-ptb",
20-
Type::CANARY => "discord-canary",
21-
Type::DEVELOPMENT => "discord-development",
18+
DiscordBranch::STABLE => "discord",
19+
DiscordBranch::PTB => "discord-ptb",
20+
DiscordBranch::CANARY => "discord-canary",
21+
DiscordBranch::DEVELOPMENT => "discord-development",
2222
};
2323

2424
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();

src/cli/run.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::{env, fs, path::Path};
22

33
use tokio::process::Command;
44

5-
use crate::{Res, error, info, r#type::Type};
5+
use crate::{branch::DiscordBranch, error, info, Res};
66

7-
pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()> {
7+
pub async fn run(release_type: DiscordBranch, args: Vec<String>, verbose: bool) -> Res<()> {
88
// create user var & create .dvm dirs
99
let user = env::var("USER")?;
1010
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
@@ -17,10 +17,10 @@ pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()
1717
}
1818

1919
let pascal_pkg = match release_type {
20-
Type::STABLE => "Discord",
21-
Type::PTB => "DiscordPTB",
22-
Type::CANARY => "DiscordCanary",
23-
Type::DEVELOPMENT => "DiscordDevelopment",
20+
DiscordBranch::STABLE => "Discord",
21+
DiscordBranch::PTB => "DiscordPTB",
22+
DiscordBranch::CANARY => "DiscordCanary",
23+
DiscordBranch::DEVELOPMENT => "DiscordDevelopment",
2424
};
2525

2626
let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
@@ -32,7 +32,8 @@ pub async fn run(release_type: Type, args: Vec<String>, verbose: bool) -> Res<()
3232
Command::new(format!("/home/{}/.dvm/{}/{}", user, pascal_pkg, pascal_pkg))
3333
.args(&args)
3434
.spawn()?
35-
.wait_with_output().await?;
35+
.wait_with_output()
36+
.await?;
3637

3738
Ok(())
3839
}

src/cli/show.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use colored::*;
99

10-
use crate::{r#type::Type, Res};
10+
use crate::{branch::DiscordBranch, Res};
1111

1212
// fn dirent(dirent: DirEntry) -> Res<(String, Type)> {
1313
// let rl_type = match dirent.file_name().to_str().unwrap() {
@@ -22,21 +22,21 @@ use crate::{r#type::Type, Res};
2222
// Ok((version, rl_type))
2323
// }
2424

25-
fn dirent_verbose(dirent: DirEntry) -> Res<(String, Type, PathBuf)> {
25+
fn dirent_verbose(dirent: DirEntry) -> Res<(String, DiscordBranch, PathBuf)> {
2626
let rl_type = match dirent.file_name().to_str().unwrap() {
27-
"Discord" => Type::STABLE,
28-
"DiscordCanary" => Type::CANARY,
29-
"DiscordPTB" => Type::PTB,
30-
"DiscordDevelopment" => Type::DEVELOPMENT,
31-
_ => Type::STABLE,
27+
"Discord" => DiscordBranch::STABLE,
28+
"DiscordCanary" => DiscordBranch::CANARY,
29+
"DiscordPTB" => DiscordBranch::PTB,
30+
"DiscordDevelopment" => DiscordBranch::DEVELOPMENT,
31+
_ => DiscordBranch::STABLE,
3232
};
3333
let path = dirent.path();
3434
let version = fs::read_to_string(path.join("version"))?.replace("\n", "");
3535

3636
Ok((version, rl_type, path))
3737
}
3838

39-
async fn needs_update(version: String, release_type: Type) -> Res<(bool, String)> {
39+
async fn needs_update(version: String, release_type: DiscordBranch) -> Res<(bool, String)> {
4040
let res = reqwest::get(format!(
4141
"https://discordapp.com/api/v8/updates/{}?platform=linux",
4242
release_type

0 commit comments

Comments
 (0)