diff --git a/src/apps/alphavet.rs b/src/apps/alphavet.rs new file mode 100644 index 00000000..3aef52a9 --- /dev/null +++ b/src/apps/alphavet.rs @@ -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 { + 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 { + 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", + } +} diff --git a/src/apps/depth.rs b/src/apps/depth.rs new file mode 100644 index 00000000..eca069df --- /dev/null +++ b/src/apps/depth.rs @@ -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 { + 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 { + 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", + } +} diff --git a/src/apps/dprint.rs b/src/apps/dprint.rs index ae58c2f1..d1f93d6e 100644 --- a/src/apps/dprint.rs +++ b/src/apps/dprint.rs @@ -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 { + 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", } } diff --git a/src/apps/gh.rs b/src/apps/gh.rs new file mode 100644 index 00000000..9c5e7a6a --- /dev/null +++ b/src/apps/gh.rs @@ -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 { + 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 { + 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", + } +} diff --git a/src/apps/gofumpt.rs b/src/apps/gofumpt.rs new file mode 100644 index 00000000..a349ccec --- /dev/null +++ b/src/apps/gofumpt.rs @@ -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 { + 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 { + 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", + } +} diff --git a/src/apps/golangci_lint.rs b/src/apps/golangci_lint.rs new file mode 100644 index 00000000..d7b0ff6a --- /dev/null +++ b/src/apps/golangci_lint.rs @@ -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 { + 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 { + 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", + } +} diff --git a/src/apps/mod.rs b/src/apps/mod.rs index 6ce32525..437d241a 100644 --- a/src/apps/mod.rs +++ b/src/apps/mod.rs @@ -1,6 +1,12 @@ //! 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; @@ -8,9 +14,6 @@ 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> { for app in all() { @@ -35,13 +38,19 @@ pub trait App { fn artifact_location(&self, version: &str, platform: Platform) -> Box; /// 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; } pub fn all() -> Vec> { 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 {}), ] } diff --git a/src/apps/scc.rs b/src/apps/scc.rs new file mode 100644 index 00000000..6148e8d3 --- /dev/null +++ b/src/apps/scc.rs @@ -0,0 +1,62 @@ +use big_s::S; + +use super::App; +use crate::detect::{Cpu, Os, Platform}; +use crate::hosting::{GithubReleaseAsset, OnlineLocation}; + +pub struct Scc {} + +impl App for Scc { + fn name(&self) -> &'static str { + "scc" + } + + fn executable(&self, platform: Platform) -> &'static str { + match platform.os { + Os::Windows => "scc.exe", + Os::Linux | Os::MacOS => "scc", + } + } + + fn homepage(&self) -> &'static str { + "https://github.com/boyter/scc" + } + + fn artifact_location(&self, version: &str, platform: Platform) -> Box { + let filename = format!( + "scc_{version}_{os}_{cpu}.{ext}", + os = os_text(platform.os), + cpu = cpu_text(platform.cpu), + ext = ext_text(platform.os) + ); + Box::new(GithubReleaseAsset { + organization: "boyter", + repo: "scc", + version: format!("v{version}"), + filename, + }) + } + + fn file_to_extract_from_archive(&self, _version: &str, platform: Platform) -> Option { + Some(S(self.executable(platform))) + } +} + +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 => "x86_64", + } +} + +fn ext_text(_os: Os) -> &'static str { + "tar.gz" +} diff --git a/src/apps/shellcheck.rs b/src/apps/shellcheck.rs index dfb1c4e9..dd3f7404 100644 --- a/src/apps/shellcheck.rs +++ b/src/apps/shellcheck.rs @@ -36,29 +36,29 @@ impl App for ShellCheck { }) } - 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 { + Some(S(self.executable(platform))) } } fn os_text(os: Os) -> &'static str { match os { - Os::Windows => "windows", Os::Linux => "linux", Os::MacOS => "darwin", + Os::Windows => "windows", } } fn cpu_text(cpu: Cpu) -> &'static str { match cpu { - Cpu::Intel64 => "x86_64", Cpu::Arm64 => "aarch64", + Cpu::Intel64 => "x86_64", } } fn ext_text(os: Os) -> &'static str { match os { - Os::Windows => "zip", Os::Linux | Os::MacOS => "tar.gz", + Os::Windows => "zip", } } diff --git a/src/apps/shfmt.rs b/src/apps/shfmt.rs index fd357bce..ce058701 100644 --- a/src/apps/shfmt.rs +++ b/src/apps/shfmt.rs @@ -35,29 +35,29 @@ impl App for Shfmt { }) } - fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> String { - String::new() + fn file_to_extract_from_archive(&self, _version: &str, _platform: Platform) -> Option { + None } } fn os_text(os: Os) -> &'static str { match os { - Os::Windows => "windows", Os::Linux => "linux", Os::MacOS => "darwin", + Os::Windows => "windows", } } fn cpu_text(cpu: Cpu) -> &'static str { match cpu { - Cpu::Intel64 => "amd64", Cpu::Arm64 => "arm64", + Cpu::Intel64 => "amd64", } } fn ext_text(os: Os) -> &'static str { match os { - Os::Windows => ".exe", Os::Linux | Os::MacOS => "", + Os::Windows => ".exe", } } diff --git a/src/archives/mod.rs b/src/archives/mod.rs index e2e4d4ee..d7fd75b5 100644 --- a/src/archives/mod.rs +++ b/src/archives/mod.rs @@ -27,13 +27,15 @@ pub trait Archive { /// extracts the given file in the given artifact to the given location on disk pub fn extract( artifact: Artifact, - path_in_archive: String, + path_in_archive: Option, path_on_disk: PathBuf, output: &dyn Output, ) -> Result { - for archive in all_archives() { - if archive.can_extract(&artifact.filename) { - return archive.extract(artifact.data, path_in_archive, path_on_disk, output); + if let Some(path_in_archive) = path_in_archive { + for archive in all_archives() { + if archive.can_extract(&artifact.filename) { + return archive.extract(artifact.data, path_in_archive, path_on_disk, output); + } } } // here the file doesn't match any of the known archives --> we assume its the binary itself