Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional apps #3

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/apps/alphavet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use super::App;
use crate::detect::{Cpu, Os, Platform};
use crate::hosting::{GithubReleaseAsset, OnlineLocation};

pub struct Alphavet {}

impl App for Alphavet {
fn name(&self) -> &'static str {
"alphavet"
}

fn executable(&self, platform: Platform) -> &'static str {
match platform.os {
Os::Windows => "alphavet.exe",
Os::Linux | Os::MacOS => "alphavet",
}
}

fn homepage(&self) -> &'static str {
"https://github.com/skx/alphavet"
}

fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation> {
let filename = format!(
"alphavet-{os}-{cpu}",
os = os_text(platform.os),
cpu = cpu_text(platform.cpu),
);
Box::new(GithubReleaseAsset {
organization: "skx",
repo: "alphavet",
version: format!("v{version}"),
filename,
})
}

fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> Option<String> {
None
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Linux => "linux",
Os::MacOS => "darwin",
Os::Windows => "windows",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Arm64 => "arm64",
Cpu::Intel64 => "amd64",
}
}
55 changes: 55 additions & 0 deletions src/apps/depth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use super::App;
use crate::detect::{Cpu, Os, Platform};
use crate::hosting::{GithubReleaseAsset, OnlineLocation};

pub struct Depth {}

impl App for Depth {
fn name(&self) -> &'static str {
"depth"
}

fn executable(&self, platform: Platform) -> &'static str {
match platform.os {
Os::Windows => "depth.exe",
Os::Linux | Os::MacOS => "depth",
}
}

fn homepage(&self) -> &'static str {
"https://github.com/KyleBanks/depth"
}

fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation> {
let filename = format!(
"depth_{version}_{os}_{cpu}",
os = os_text(platform.os),
cpu = cpu_text(platform.cpu),
);
Box::new(GithubReleaseAsset {
organization: "KyleBanks",
repo: "depth",
version: format!("v{version}"),
filename,
})
}

fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> Option<String> {
None
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Linux => "linux",
Os::MacOS => "darwin",
Os::Windows => "windows",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Arm64 => "arm",
Cpu::Intel64 => "amd64",
}
}
8 changes: 4 additions & 4 deletions src/apps/dprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ impl App for Dprint {
})
}

fn file_to_extract_from_archive(&self, _version: &str, platform: Platform) -> String {
S(self.executable(platform))
fn file_to_extract_from_archive(&self, _version: &str, platform: Platform) -> Option<String> {
Some(S(self.executable(platform)))
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Windows => "pc-windows-msvc",
Os::Linux => "unknown-linux-gnu",
Os::MacOS => "apple-darwin",
Os::Windows => "pc-windows-msvc",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Intel64 => "x86_64",
Cpu::Arm64 => "aarch64",
Cpu::Intel64 => "x86_64",
}
}
67 changes: 67 additions & 0 deletions src/apps/gh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use super::App;
use crate::detect::{Cpu, Os, Platform};
use crate::hosting::{GithubReleaseAsset, OnlineLocation};

pub struct Gh {}

impl App for Gh {
fn name(&self) -> &'static str {
"gh"
}

fn executable(&self, platform: Platform) -> &'static str {
match platform.os {
Os::Windows => "dprint.exe",
Os::Linux | Os::MacOS => "dprint",
}
}

fn homepage(&self) -> &'static str {
"https://cli.github.com"
}

fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation> {
let filename = format!(
"gh_{version}_{os}_{cpu}.{ext}",
os = os_text(platform.os),
cpu = cpu_text(platform.cpu),
ext = ext_text(platform.os)
);
Box::new(GithubReleaseAsset {
organization: "cli",
repo: "cli",
version: format!("v{version}"),
filename,
})
}

fn file_to_extract_from_archive(
&self,
version: &str,
Platform { os, cpu }: Platform,
) -> Option<String> {
Some(format!("gh_{version}_{os}_{cpu}/bin/gh",))
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Linux => "linux",
Os::MacOS => "macOS",
Os::Windows => "windows",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Arm64 => "arm64",
Cpu::Intel64 => "amd64",
}
}

fn ext_text(os: Os) -> &'static str {
match os {
Os::Linux => "tgz",
Os::Windows | Os::MacOS => "zip",
}
}
55 changes: 55 additions & 0 deletions src/apps/gofumpt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use super::App;
use crate::detect::{Cpu, Os, Platform};
use crate::hosting::{GithubReleaseAsset, OnlineLocation};

pub struct Gofumpt {}

impl App for Gofumpt {
fn name(&self) -> &'static str {
"gofumpt"
}

fn executable(&self, platform: Platform) -> &'static str {
match platform.os {
Os::Windows => "gofumpt.exe",
Os::Linux | Os::MacOS => "gofumpt",
}
}

fn homepage(&self) -> &'static str {
"https://github.com/mvdan/gofumpt"
}

fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation> {
let filename = format!(
"gofumpt_{version}_{os}_{cpu}",
os = os_text(platform.os),
cpu = cpu_text(platform.cpu),
);
Box::new(GithubReleaseAsset {
organization: "mvdan",
repo: "gofumpt",
version: version.to_string(),
filename,
})
}

fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> Option<String> {
None
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Linux => "linux",
Os::MacOS => "darwin",
Os::Windows => "windows",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Arm64 => "arm64",
Cpu::Intel64 => "amd64",
}
}
63 changes: 63 additions & 0 deletions src/apps/golangci_lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use super::App;
use crate::detect::{Cpu, Os, Platform};
use crate::hosting::{GithubReleaseAsset, OnlineLocation};

pub struct GolangCiLint {}

impl App for GolangCiLint {
fn name(&self) -> &'static str {
"golangci-lint"
}

fn executable(&self, platform: Platform) -> &'static str {
match platform.os {
Os::Windows => "golangci-lint.exe",
Os::Linux | Os::MacOS => "golangci-lint",
}
}

fn homepage(&self) -> &'static str {
"https://github.com/golangci/golangci-lint"
}

fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation> {
let filename = format!(
"golangci-lint-v{version}-{os}-{cpu}.{ext}",
os = os_text(platform.os),
cpu = cpu_text(platform.cpu),
ext = ext_text(platform.os),
);
Box::new(GithubReleaseAsset {
organization: "golangci",
repo: "golangci-lint",
version: format!("v{version}"),
filename,
})
}

fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> Option<String> {
None
}
}

fn os_text(os: Os) -> &'static str {
match os {
Os::Linux => "linux",
Os::MacOS => "darwin",
Os::Windows => "windows",
}
}

fn cpu_text(cpu: Cpu) -> &'static str {
match cpu {
Cpu::Arm64 => "arm64",
Cpu::Intel64 => "amd64",
}
}

fn ext_text(os: Os) -> &'static str {
match os {
Os::Linux | Os::MacOS => "tar.gz",
Os::Windows => "zip",
}
}
23 changes: 16 additions & 7 deletions src/apps/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
//! all applications that run-this-app can run

mod alphavet;
mod depth;
mod dprint;
mod gh;
mod gofumpt;
mod golangci_lint;
mod scc;
mod shellcheck;
mod shfmt;

use crate::detect::Platform;
use crate::error::UserError;
use crate::hosting::OnlineLocation;
use crate::Result;
use dprint::Dprint;
use shellcheck::ShellCheck;
use shfmt::Shfmt;

pub fn lookup(name: &str) -> Result<Box<dyn App>> {
for app in all() {
Expand All @@ -35,13 +38,19 @@ pub trait App {
fn artifact_location(&self, version: &str, platform: Platform) -> Box<dyn OnlineLocation>;

/// the name of the executable file in the archive
fn file_to_extract_from_archive(&self, version: &str, platform: Platform) -> String;
fn file_to_extract_from_archive(&self, version: &str, platform: Platform) -> Option<String>;
}

pub fn all() -> Vec<Box<dyn App>> {
vec![
Box::new(Dprint {}),
Box::new(ShellCheck {}),
Box::new(Shfmt {}),
Box::new(alphavet::Alphavet {}),
Box::new(depth::Depth {}),
Box::new(dprint::Dprint {}),
Box::new(gh::Gh {}),
Box::new(gofumpt::Gofumpt {}),
Box::new(golangci_lint::GolangCiLint {}),
Box::new(scc::Scc {}),
Box::new(shellcheck::ShellCheck {}),
Box::new(shfmt::Shfmt {}),
]
}
Loading
Loading