-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.rs
73 lines (66 loc) · 2.07 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use anyhow::Result;
use clap::{AppSettings, Parser};
mod pypi;
use pypi::{request_package_info, PyPIData};
/// Python package manager written in Rust
#[derive(Parser, Debug)]
#[clap(global_setting = AppSettings::DeriveDisplayOrder)]
enum Opt {
/// Install packages.
Install {},
/// Download packages.
Download {
#[clap(short = 'n', long = "name")]
name: String,
#[clap(short = 'i', long = "index", default_value = "https://pypi.org/")]
index: String,
},
/// Uninstall packages.
Uninstall {},
/// List installed packages.
List {},
/// Show information about installed packages.
Show {},
/// Output installed packages in requirements format.
Freeze {},
/// Verify installed packages have compatible dependencies.
Check {},
/// Manage local and global configuration.
Config {},
/// Search PyPI for packages.
Search {},
/// Inspect and manage pip's wheel cache.
Cache {},
/// Inspect information available from package indexes.
Index {},
/// Build wheels from your requirements.
Wheel {},
/// Compute hashes of package archives.
Hash {},
/// A helper command used for command completion.
Completion {},
/// Show information useful for debugging.
Debug {},
/// Show help for commands.
Help {},
}
fn download_package(package_name: String, package_index: &String) -> Result<()> {
let package_info: PyPIData = request_package_info(&package_name, package_index)?;
// Example of getting data this will be more robust as the
// PyPIData struct gets expanded (meaning less calls to .get())
let latest_version = package_info.info.version;
println!("Latest Version of {} is {}", package_name, latest_version);
Ok(())
}
fn main() {
let opt = Opt::parse();
println!("{:#?}", opt);
match opt {
Opt::Download { name, index } => {
println!("Package name {:?}", name);
println!("Index name: {:?}", index);
let _ = download_package(name, &index);
}
_ => todo!(),
}
}