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

Rework contract init #1625

Draft
wants to merge 2 commits into
base: init-deprecate
Choose a base branch
from
Draft

Rework contract init #1625

wants to merge 2 commits into from

Conversation

Ifropc
Copy link
Contributor

@Ifropc Ifropc commented Sep 25, 2024

What

Rework contract init. Not it does:

  1. When run on empty/non-existing directory: initialize cargo worspace and add hello-world contract there
  2. When running on an existing project root: add a new hello-world contract package

Why

Changes according to #1586

Known limitations

--overwrite support has been removed. If we decide to keep it in #1628, this PR should return it back

Initialize a Soroban project with an example contract
Initialize a Soroban contract.

When running with empty or non-existent `--project-path`, this command will generate a template Cargo workspace project and add a sample contract package. When running in the existing Cargo project, it will add a new package for a sample contract with a given `--name`.
Copy link
Member

Choose a reason for hiding this comment

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

isn't the project path positional? You don't actually have --project-path.

use crate::commands::contract::init::Error::{
AlreadyExists, PathExistsNotCargoProject, PathExistsNotDir,
};
use crate::{commands::global, print};

#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
pub project_path: String,
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be updated to Option<project_path>. This will require either project_path or --name to be provided; if you run the command like stellar contract init, it should error.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't project path always required? Name is just specifying the name of the contract in the workspace, but presumably we still need to tell the tool where the workspace is.

default_value = "",
long_help = "An optional flag to pass in a url for a frontend template repository."
action = clap::ArgAction::HelpLong,
long_help = "This argument has been deprecated and will be removed in the future versions of CLI. You can still clone examples from the repo https://github.com/stellar/soroban-examples",
Copy link
Member

Choose a reason for hiding this comment

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

Given that these deprecated switches are in fact noop, I think we should mention that the switch doesn't do anything anymore. The way is phrased right now gives the impression it worked, but won't in the future.

Copy link
Member

Choose a reason for hiding this comment

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

If the switches don't do anything anymore, we should remove them so folks get a hard error if they try to use it.

Comment on lines +161 to 163
if project_path.exists() {
return Err(AlreadyExists(self.args.name.clone()));
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep allowing users to overwrite a project. It's a great way to upgrade all your project, because you can undo undesired changes with git, while keeping everything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior has changed, so I don't think this flag is needed anymore

@Ifropc Ifropc changed the base branch from main to init-deprecate September 25, 2024 22:11
@Ifropc Ifropc marked this pull request as draft September 26, 2024 15:50
@Ifropc
Copy link
Contributor Author

Ifropc commented Sep 26, 2024

I'm converting this PR back to draft, I think my original implementation is not what we would like to move forward with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog (Not Ready)
Development

Successfully merging this pull request may close these issues.

3 participants