Add bootstrap
binary
This commit is contained in:
parent
00e48a9f9a
commit
e345ca6abb
711
Cargo.lock
generated
711
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@ -7,20 +7,26 @@ license = "GPL-3.0-only"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [ "cli", "tar" ]
|
members = [ "bootstrap", "cli", "tar" ]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "hpk"
|
name = "hpk"
|
||||||
path = "src/hpk.rs"
|
path = "src/hpk.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "bootstrap"
|
||||||
|
path = "src/bootstrap.rs"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
clap = "4.1"
|
clap = "4.1"
|
||||||
|
cli = { path = "cli" }
|
||||||
deku = "0.16"
|
deku = "0.16"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { workspace = true }
|
bootstrap = { path = "bootstrap" }
|
||||||
|
clap.workspace = true
|
||||||
|
cli.workspace = true
|
||||||
deku.workspace = true
|
deku.workspace = true
|
||||||
cli = { path = "cli" }
|
|
||||||
rayon = "1.7"
|
rayon = "1.7"
|
||||||
ron = "0.8"
|
ron = "0.8"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
@ -32,6 +38,10 @@ zstd = "0.12"
|
|||||||
version = "0.4"
|
version = "0.4"
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
|
|
||||||
|
[dependencies.reqwest]
|
||||||
|
version = "0.11"
|
||||||
|
features = ["blocking"]
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
features = ["derive"]
|
features = ["derive"]
|
||||||
|
11
bootstrap/Cargo.toml
Normal file
11
bootstrap/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "bootstrap"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cli.workspace = true
|
||||||
|
clap.workspace = true
|
||||||
|
clap_complete = "4.1"
|
||||||
|
clap_complete_nushell = "0.1"
|
||||||
|
clap_mangen = "0.2"
|
86
bootstrap/src/lib.rs
Normal file
86
bootstrap/src/lib.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
use {
|
||||||
|
clap_complete::{generate_to, shells},
|
||||||
|
clap_complete_nushell::Nushell,
|
||||||
|
std::{error::Error, fs, ops::Deref, path::{Path, PathBuf}},
|
||||||
|
};
|
||||||
|
|
||||||
|
static PROGNAME: &str = "hpk";
|
||||||
|
|
||||||
|
fn completions<P: Deref<Target = Path>>(dir: P) -> Result<(), Box<dyn Error>> {
|
||||||
|
println!("Generating completions:");
|
||||||
|
let mut cmd = cli::cli();
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
["share", "bash-completion", "completions"]
|
||||||
|
.iter()
|
||||||
|
.for_each(|d| outdir.push(d));
|
||||||
|
if !outdir.exists() {
|
||||||
|
fs::create_dir_all(&outdir)?;
|
||||||
|
}
|
||||||
|
let path = generate_to(shells::Bash, &mut cmd, PROGNAME, outdir)?;
|
||||||
|
println!(" {}", path.display());
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
["share", "zsh", "site-functions"]
|
||||||
|
.iter()
|
||||||
|
.for_each(|d| outdir.push(d));
|
||||||
|
if !outdir.exists() {
|
||||||
|
fs::create_dir_all(&outdir)?;
|
||||||
|
}
|
||||||
|
let path = generate_to(shells::Zsh, &mut cmd, PROGNAME, outdir)?;
|
||||||
|
println!(" {}", path.display());
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
["share", "fish", "completions"]
|
||||||
|
.iter()
|
||||||
|
.for_each(|d| outdir.push(d));
|
||||||
|
if !outdir.exists() {
|
||||||
|
fs::create_dir_all(&outdir)?;
|
||||||
|
}
|
||||||
|
let path = generate_to(shells::Fish, &mut cmd, PROGNAME, outdir)?;
|
||||||
|
println!(" {}", path.display());
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
["share", "pwsh", "completions"]
|
||||||
|
.iter()
|
||||||
|
.for_each(|d| outdir.push(d));
|
||||||
|
if !outdir.exists() {
|
||||||
|
fs::create_dir_all(&outdir)?;
|
||||||
|
}
|
||||||
|
let path = generate_to(shells::PowerShell, &mut cmd, PROGNAME, outdir)?;
|
||||||
|
println!(" {}", path.display());
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
["share", "nu", "completions"]
|
||||||
|
.iter()
|
||||||
|
.for_each(|d| outdir.push(d));
|
||||||
|
if !outdir.exists() {
|
||||||
|
fs::create_dir_all(&outdir)?;
|
||||||
|
}
|
||||||
|
let path = generate_to(Nushell, &mut cmd, PROGNAME, outdir)?;
|
||||||
|
println!(" {}", path.display());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_bin<P: Deref<Target = Path>>(dir: P, arch: Option<String>) -> Result<(), Box<dyn Error>> {
|
||||||
|
println!("Copying binary:");
|
||||||
|
let mut bindir = dir.to_path_buf();
|
||||||
|
bindir.push("bin");
|
||||||
|
if !bindir.exists() {
|
||||||
|
fs::create_dir_all(&bindir)?;
|
||||||
|
}
|
||||||
|
let mut outfile = bindir;
|
||||||
|
outfile.push("hpk");
|
||||||
|
let infile: PathBuf = if let Some(arch) = arch {
|
||||||
|
["target", &arch, "release", PROGNAME].iter().collect()
|
||||||
|
} else {
|
||||||
|
["target", "release", PROGNAME].iter().collect()
|
||||||
|
};
|
||||||
|
if !infile.exists() {
|
||||||
|
eprintln!("Error: you must run \"cargo build --release\" first");
|
||||||
|
}
|
||||||
|
fs::copy(&infile, &outfile)?;
|
||||||
|
println!(" {} -> {}", infile.display(), outfile.display());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn install(dir: PathBuf, arch: Option<String>) -> Result<(), Box<dyn Error>> {
|
||||||
|
copy_bin(dir.as_path(), arch)?;
|
||||||
|
completions(dir.as_path())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
27
src/bootstrap.rs
Normal file
27
src/bootstrap.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use {
|
||||||
|
clap::{Arg, Command},
|
||||||
|
std::error::Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let matches = Command::new("bootstrap")
|
||||||
|
.about("install the software")
|
||||||
|
.author("Nathan Fisher")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.args([
|
||||||
|
Arg::new("arch")
|
||||||
|
.help("the architecture of the binary to be installed")
|
||||||
|
.short('a')
|
||||||
|
.long("arch")
|
||||||
|
.num_args(1),
|
||||||
|
Arg::new("output")
|
||||||
|
.help("the output directory for the installation")
|
||||||
|
.required(true)
|
||||||
|
.num_args(1)
|
||||||
|
])
|
||||||
|
.get_matches();
|
||||||
|
let outdir = matches.get_one::<String>("output").unwrap().to_string().into();
|
||||||
|
let arch = matches.get_one::<String>("arch").map(|x| x.to_string());
|
||||||
|
bootstrap::install(outdir, arch)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user