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

chore: support specify contract path input with or without -p flag #361

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ndkazu
Copy link

@ndkazu ndkazu commented Dec 3, 2024

Description

This PR is addressing issue #350.
Allow pop-cli to supports two ways to to specify the path to a contract or artifact file: using the -p flag or specifying the path directly without it:

pop call contract -p ../contract.json 

and

pop call contract ../contract.json

should both be possible.

Implementation

Two arguments are used to specify the path: One Optional, and one positional:

#[arg(long,required = false)]
	pub(crate) path: Option<PathBuf>,
	#[arg(value_name = "PATH",required = false)]
	pub(crate) path1: Option<PathBuf>,

The following contract-related commands will be upgraded

  • pop build
  • pop up contract
  • pop call contract

@AlexD10S
Copy link
Collaborator

AlexD10S commented Dec 4, 2024

Thanks for your interest in contributing to pop-cli!
I’ve reviewed your approach, and maintaining a second argument path1 might not be the cleanest way to solve this.
You might want to explore using positional arguments, as discussed here clap-rs/clap#2260, or consider the use of subcommands (https://docs.rs/clap/latest/clap/trait.Subcommand.html) instead.

@ndkazu
Copy link
Author

ndkazu commented Dec 6, 2024

Thanks for your interest in contributing to pop-cli! I’ve reviewed your approach, and maintaining a second argument path1 might not be the cleanest way to solve this. You might want to explore using positional arguments, as discussed here clap-rs/clap#2260, or consider the use of subcommands (https://docs.rs/clap/latest/clap/trait.Subcommand.html) instead.

Hello, I looked into it, and it seems to me that what we're trying to do is closer to this, and this.
and from what I understood from these discussions involving the Clap devTeam, it seems like using two arguments is the way to go(maybe not the way I did it though... maybe use required_unless = ... instead of required = ... ). An experimental module exists here, but I don't think the CLAP team is wiling to consider it.

@ndkazu
Copy link
Author

ndkazu commented Dec 7, 2024

@AlexD10S , I made a cleaner version of my first suggestion (modifications are minimal, and limited to pop build ...). I am still looking for other (less invasive?) routes, but based on my previous comment, let me know if it makes sense to propagate this method to pop up contract & pop call contract.

@AlexD10S
Copy link
Collaborator

@AlexD10S , I made a cleaner version of my first suggestion (modifications are minimal, and limited to pop build ...). I am still looking for other (less invasive?) routes, but based on my previous comment, let me know if it makes sense to propagate this method to pop up contract & pop call contract.

Thanks! Running the CI to check all tests pass, and I'll do a proper review

@ndkazu
Copy link
Author

ndkazu commented Dec 14, 2024

@AlexD10S , I made a cleaner version of my first suggestion (modifications are minimal, and limited to pop build ...). I am still looking for other (less invasive?) routes, but based on my previous comment, let me know if it makes sense to propagate this method to pop up contract & pop call contract.

Thanks! Running the CI to check all tests pass, and I'll do a proper review

I saw that the CLI was failing, and did a cargo +nightly fmt as a tentative to fix the error.

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 75.62%. Comparing base (3f86d18) to head (0cbabc5).
Report is 214 commits behind head on main.

Files with missing lines Patch % Lines
crates/pop-cli/src/commands/build/mod.rs 9.09% 10 Missing ⚠️
@@            Coverage Diff             @@
##             main     #361      +/-   ##
==========================================
+ Coverage   74.29%   75.62%   +1.33%     
==========================================
  Files          56       59       +3     
  Lines       11233    12725    +1492     
  Branches    11233    12725    +1492     
==========================================
+ Hits         8345     9623    +1278     
- Misses       1746     1806      +60     
- Partials     1142     1296     +154     
Files with missing lines Coverage Δ
crates/pop-cli/src/commands/build/mod.rs 47.72% <9.09%> (-2.28%) ⬇️

... and 25 files with indirect coverage changes

@ndkazu
Copy link
Author

ndkazu commented Dec 17, 2024

Any update? should I propagate the modification to pop up contract & pop call contract ?

@evilrobot-01
Copy link
Contributor

Any update? should I propagate the modification to pop up contract & pop call contract ?

Sorry for the delay, we have been readying a release. @AlexD10S could you provide some feedback on next steps here please?

Copy link
Collaborator

@AlexD10S AlexD10S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for sharing these resources! They were very helpful in understanding the best approach. While I'm not thrilled about it, it seems that keeping the two arguments is the most practical solution, great job.

A couple of quick changes:

If you run pop in your parachain or contract folder, there’s no need to specify the path. That's why we changed the argument to Option.
You could remove required_unless_present and probably makes sense to use index = 1.

It might also be helpful to add conflicts_with = "path" so that users don’t accidentally specify both positional and named paths, like this:

pop build ../my_contract --path ../my_contract_2

Here's an example of how the argument definition could look:

/// Directory path without flag for your project [default: current directory]
#[arg(value_name = "PATH", index = 1, conflicts_with = "path")]
pub(crate) path_pos: Option<PathBuf>,

Finally, with this optional path in mind, the code where you determine project_path can be simplified to something like this:

 let project_path = if let Some(path_pos) = args.path_pos {
        Some(path_pos) // Use positional path if present
    } else {
        args.path // Otherwise, use the named path
    };

Great work so far, and thank you for your patience while I got around to reviewing this! Apologies for the delay.

Copy link
Collaborator

@AlexD10S AlexD10S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!
I left some comment mainly to refactor repetitive code.
The important thing to fix are the unit tests that are failing. I think it can be because you specify both path and path_pos in the tests and then the result is not the expected.
Review the tests and adjust it. I'd probably leave path and path_pos to None in most of the tests except one where use path_pos or have a specific one to test the path_pos functionality

You can test them locally with: cargo test --lib --bins.

crates/pop-cli/src/commands/call/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/src/commands/call/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/src/commands/call/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/src/commands/call/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/src/commands/up/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/tests/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/tests/contract.rs Outdated Show resolved Hide resolved
crates/pop-cli/tests/contract.rs Outdated Show resolved Hide resolved
@AlexD10S AlexD10S changed the title Support specify contract path input with or without -p flag chore: support specify contract path input with or without -p flag Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants