-
Notifications
You must be signed in to change notification settings - Fork 36
Some feedback #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
91b6f6e
AsRef<Path> -> Into<PathBuf>
steveklabnik 13107eb
Prefer &str over &String as a parameter
steveklabnik 471b418
Prefer & to .as_str()
steveklabnik c8dc00d
Use format strings
steveklabnik 951c77a
(partially) address TOCTOU
steveklabnik 88c2898
Remove an unwrap
steveklabnik dadbffb
Remove unwrap in from_registry
steveklabnik b92a12e
Remove the rest of the unwraps from package.rs
steveklabnik d0098b3
remove unused main function in lib.rs
steveklabnik e68c4c8
integrate anyhow
steveklabnik 387288c
Use tokio main macro
steveklabnik 201a6d6
Re-work errors slightly
steveklabnik ebde746
deduplicate a hashmap lookup
steveklabnik 77e8554
Remove unneeded allocation
steveklabnik cb1f74c
Clippy suggestion: nonexhastive enum
steveklabnik edc6089
Another opportunity to use format strings for clarity
steveklabnik e85e6ca
or -> or_else
steveklabnik cc9c0e2
or_else -> map_err
steveklabnik 909d8ad
unwrap instead of let _
steveklabnik 9387919
two more or -> map_err
steveklabnik 5d8927c
Remove unneeded conversion
steveklabnik 4614358
Use #[from]
steveklabnik f8f2d93
remove rayon
steveklabnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,23 @@ | ||
| use clap::{Arg, Command}; | ||
| use clap::{Parser, Subcommand}; | ||
|
|
||
| fn init_package_command() -> Command { | ||
| Command::new("init").about("Initialize a package") | ||
| /// Experimental package manager for node.js written in rust. | ||
| #[derive(Parser, Debug)] | ||
| #[command(author, version, about, long_about = None)] | ||
| pub struct Cli { | ||
| #[command(subcommand)] | ||
| pub subcommand: Subcommands, | ||
| } | ||
|
|
||
| fn add_package_command() -> Command { | ||
| Command::new("add").about("Add a package").arg(Arg::new("package")) | ||
| #[derive(Subcommand, Debug)] | ||
| pub enum Subcommands { | ||
| Init, | ||
| Add(AddArgs), | ||
| } | ||
|
|
||
| pub fn get_commands() -> Command { | ||
| Command::new("pacquet") | ||
| .bin_name("pacquet") | ||
| .version("alpha") | ||
| .author("Yagiz Nizipli") | ||
| .arg_required_else_help(true) | ||
| .subcommands([add_package_command(), init_package_command()]) | ||
| #[derive(Parser, Debug)] | ||
| /// Add a package | ||
| pub struct AddArgs { | ||
| /// Name of the package | ||
| #[arg(short, long)] | ||
| pub package: String, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,38 @@ | ||
| mod commands; | ||
|
|
||
| use anyhow::{Context, Result}; | ||
| use clap::Parser; | ||
| use commands::{Cli, Subcommands}; | ||
| use pacquet_package_json::PackageJson; | ||
| use pacquet_registry::RegistryManager; | ||
|
|
||
| use crate::commands::get_commands; | ||
|
|
||
| pub async fn run_commands() { | ||
| let matches = get_commands().get_matches(); | ||
| let current_directory = std::env::current_dir().expect("current directory should exist"); | ||
| pub async fn run_commands() -> Result<()> { | ||
| let current_directory = | ||
| std::env::current_dir().context("problem fetching current directory")?; | ||
| let cache_directory = current_directory.join(".pacquet").as_path().to_owned(); | ||
| let node_modules = current_directory.join("node_modules").as_path().to_owned(); | ||
|
|
||
| if !cache_directory.exists() { | ||
| std::fs::create_dir(&cache_directory).expect("cache folder creation failed"); | ||
| std::fs::create_dir(&cache_directory).context("cache folder creation failed")?; | ||
| } | ||
|
|
||
| if !node_modules.exists() { | ||
| std::fs::create_dir(&node_modules).expect("node_modules folder creation failed"); | ||
| std::fs::create_dir(&node_modules).context("node_modules folder creation failed")?; | ||
| } | ||
|
|
||
| let mut registry_manager = RegistryManager::new(cache_directory); | ||
|
|
||
| if let Some(subcommand) = matches.subcommand_matches("add") { | ||
| if let Some(package_name) = subcommand.get_one::<String>("package") { | ||
| registry_manager.get_package(package_name).await.expect("TODO: panic message"); | ||
| let cli = Cli::parse(); | ||
|
|
||
| match &cli.subcommand { | ||
| Subcommands::Init => { | ||
| let pkg = PackageJson::from_current_directory(); | ||
| pkg.create_if_needed(); | ||
| } | ||
| Subcommands::Add(args) => { | ||
| registry_manager.get_package(&args.package).await?; | ||
| } | ||
| } else if matches.subcommand_matches("init").is_some() { | ||
| let pkg = PackageJson::from_current_directory(); | ||
| pkg.create_if_needed(); | ||
| } | ||
| } | ||
|
|
||
| pub fn main() { | ||
| tokio::runtime::Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .unwrap() | ||
| .block_on(run_commands()) | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| pub fn main() { | ||
| tokio::runtime::Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .unwrap() | ||
| .block_on(pacquet_cli::run_commands()) | ||
| use anyhow::Result; | ||
|
|
||
| #[tokio::main(flavor = "current_thread")] | ||
|
anonrig marked this conversation as resolved.
|
||
| pub async fn main() -> Result<()> { | ||
| pacquet_cli::run_commands().await | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.