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

refactor: renaming, removing unused features and styling #33

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
[submodule "templates/ept"]
path = templates/ept
url = git@github.com:paritytech/extended-parachain-template.git

[submodule "templates/vanilla-parachain"]
path = templates/vanilla-parachain
url = git@github.com:r0guelabs/vanilla-parachain.git
[submodule "templates/base-parachain"]
path = templates/base-parachain
url = git@github.com:r0gue-io/base-parachain.git

24 changes: 24 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Basic
edition = "2021"
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
# Format comments
comment_width = 100
wrap_comments = true
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Use `pop` to either clone of your existing templates or instantiate a new parach
```sh
# Create a minimal parachain template
pop new parachain my-app
# Get the extended-parachain-template
pop new parachain my-app ept
# Get a pallet-contracts enabled template
pop new parachain my-app cpt
# Get a evm compatible parachain template
Expand Down
18 changes: 11 additions & 7 deletions src/commands/build/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use crate::engines::contract_engine::build_smart_contract;

#[derive(Args)]
pub struct BuildContractCommand {
#[arg(short = 'p', long = "path", help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
#[arg(
short = 'p',
long = "path",
help = "Path for the contract project, [default: current directory]"
)]
pub(crate) path: Option<PathBuf>,
}

impl BuildContractCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
build_smart_contract(&self.path)?;
log::info("The smart contract has been successfully built.")?;
Ok(())
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
build_smart_contract(&self.path)?;
log::info("The smart contract has been successfully built.")?;
Ok(())
}
}
14 changes: 7 additions & 7 deletions src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ pub mod contract;
#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
pub(crate) struct BuildArgs {
#[command(subcommand)]
pub command: BuildCommands,
#[command(subcommand)]
pub command: BuildCommands,
}

#[derive(Subcommand)]
pub(crate) enum BuildCommands {
/// Compiles the contract, generates metadata, bundles both together in a
/// `<name>.contract` file
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::BuildContractCommand),
/// Compiles the contract, generates metadata, bundles both together in a
/// `<name>.contract` file
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::BuildContractCommand),
}
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod new;
pub(crate) mod build;
pub(crate) mod up;
pub(crate) mod new;
pub(crate) mod test;
pub(crate) mod up;
60 changes: 31 additions & 29 deletions src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,43 @@ use crate::engines::contract_engine::create_smart_contract;

#[derive(Args)]
pub struct NewContractCommand {
#[arg(help = "Name of the contract")]
pub(crate) name: String,
#[arg(short = 'p', long = "path", help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
#[arg(help = "Name of the contract")]
pub(crate) name: String,
#[arg(
short = 'p',
long = "path",
help = "Path for the contract project, [default: current directory]"
)]
pub(crate) path: Option<PathBuf>,
}

impl NewContractCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_smart_contract(self.name.clone(), &self.path)?;
log::info(format!(
"Smart contract created. Move to the dir {:?}",
self.path.clone().unwrap_or(PathBuf::from(format!("{}", self.name))).display()
))?;
Ok(())
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_smart_contract(self.name.clone(), &self.path)?;
log::info(format!(
"Smart contract created. Move to the dir {:?}",
self.path.clone().unwrap_or(PathBuf::from(format!("{}", self.name))).display()
))?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use super::*;
use std::fs;

#[test]
fn test_new_contract_command_execute() -> anyhow::Result<()> {
let command = NewContractCommand {
name: "test_contract".to_string(),
path: Some(PathBuf::new())
};
let result = command.execute();
assert!(result.is_ok());

// Clean up
if let Err(err) = fs::remove_dir_all("test_contract") {
eprintln!("Failed to delete directory: {}", err);
}
Ok(())
}
#[test]
fn test_new_contract_command_execute() -> anyhow::Result<()> {
let command =
NewContractCommand { name: "test_contract".to_string(), path: Some(PathBuf::new()) };
let result = command.execute();
assert!(result.is_ok());

// Clean up
if let Err(err) = fs::remove_dir_all("test_contract") {
eprintln!("Failed to delete directory: {}", err);
}
Ok(())
}
}
28 changes: 14 additions & 14 deletions src/commands/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ pub mod parachain;
#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct NewArgs {
#[command(subcommand)]
pub command: NewCommands,
#[command(subcommand)]
pub command: NewCommands,
}

#[derive(Subcommand)]
pub enum NewCommands {
/// Generate a new parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::NewParachainCommand),
/// Generate a new pallet template
#[cfg(feature = "parachain")]
#[clap(alias = "m")] // (m)odule, as p used above
Pallet(pallet::NewPalletCommand),
/// Generate a new smart contract template
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::NewContractCommand),
/// Generate a new parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::NewParachainCommand),
/// Generate a new pallet template
#[cfg(feature = "parachain")]
#[clap(alias = "m")] // (m)odule, as p used above
Pallet(pallet::NewPalletCommand),
/// Generate a new smart contract template
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::NewContractCommand),
}
44 changes: 21 additions & 23 deletions src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
use crate::engines::pallet_engine::{create_pallet_template, TemplatePalletConfig};
use clap::Args;
use crate::engines::pallet_engine::{TemplatePalletConfig, create_pallet_template};

#[derive(Args)]
pub struct NewPalletCommand {
#[arg(help = "Name of the pallet", default_value = "pallet-template")]
pub(crate) name: String,
#[arg(short, long, help = "Name of authors", default_value = "Anonymous")]
pub(crate) authors: Option<String>,
#[arg(
short,
long,
help = "Pallet description",
default_value = "Frame Pallet"
)]
pub(crate) description: Option<String>,
#[arg(short = 'p', long = "path", help = "Path to the pallet, [default: current directory]")]
pub(crate) path: Option<String>,
#[arg(help = "Name of the pallet", default_value = "pallet-template")]
pub(crate) name: String,
#[arg(short, long, help = "Name of authors", default_value = "Anonymous")]
pub(crate) authors: Option<String>,
#[arg(short, long, help = "Pallet description", default_value = "Frame Pallet")]
pub(crate) description: Option<String>,
#[arg(short = 'p', long = "path", help = "Path to the pallet, [default: current directory]")]
pub(crate) path: Option<String>,
}

impl NewPalletCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_pallet_template(self.path.clone(), TemplatePalletConfig {
name: self.name.clone(),
authors: self.authors.clone().expect("default values"),
description: self.description.clone().expect("default values"),
})?;
Ok(())
}
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_pallet_template(
self.path.clone(),
TemplatePalletConfig {
name: self.name.clone(),
authors: self.authors.clone().expect("default values"),
description: self.description.clone().expect("default values"),
},
)?;
Ok(())
}
}
Loading