Skip to content

Commit

Permalink
feat(cli): print banner on help and running with no args
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed May 3, 2024
1 parent 9d368c0 commit 61641df
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ eula = false
[dependencies]
arc-swap = "1.7.1"
clap = { version = "4.5.4", features = ["derive"] }
color-print = "0.3.6"
console = "0.15.8"
dirs = "5.0.1"
flate2 = "1.0.28"
Expand Down
14 changes: 7 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::cmd;
use crate::{cmd, BANNER};

use clap::Parser;

#[derive(Parser)]
#[clap(version, about, long_about = None)]
#[clap(version, about, long_about = Some(BANNER))]
#[clap(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
Expand All @@ -20,11 +20,11 @@ impl Cli {
pub async fn exec(self) -> miette::Result<()> {
match self.cmd {
Some(cmd) => cmd.exec().await,
None => install_latest().await,
None => {
println!("\n {}\n", BANNER.trim_start());

cmd::install::latest().await
}
}
}
}

async fn install_latest() -> miette::Result<()> {
cmd::install::Args::latest().exec().await
}
8 changes: 5 additions & 3 deletions src/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ impl Args {
}

pub async fn exec(self) -> miette::Result<()> {
println!("{}", BANNER);

let ctx = crate::ctx::instance();
let ctx = ctx::instance();
let octocrab = octocrab::instance();

let aiken_root = root_dir()?;
Expand Down Expand Up @@ -169,6 +167,10 @@ impl Args {
}
}

pub async fn latest() -> miette::Result<()> {
Args::latest().exec().await
}

fn asset_name(tag_name: &str) -> String {
let os = match env::consts::OS {
"macos" => "darwin",
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use miette::IntoDiagnostic;

use crate::utils::root_dir;
use crate::{ctx, utils::root_dir};

/// List available aiken versions
#[derive(clap::Args)]
Expand All @@ -12,7 +12,7 @@ pub struct Args {

impl Args {
pub async fn exec(self) -> miette::Result<()> {
let ctx = crate::ctx::instance();
let ctx = ctx::instance();

if self.installed {
let aiken_root = root_dir()?;
Expand Down
23 changes: 9 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ mod ctx;
mod utils;

pub use cli::Cli;
use indoc::indoc;

pub const BANNER: &str = indoc! {
r#"================================================================================
pub const BANNER: &str = color_print::cstr! {
r#"
░█▀▀▄░▀█▀░▒█░▄▀░▒█▀▀▀░▒█▄░▒█ Modern and modular toolkit
▒█▄▄█░▒█░░▒█▀▄░░▒█▀▀▀░▒█▒█▒█ for Cardano Smart Contract development.
▒█░▒█░▄█▄░▒█░▒█░▒█▄▄▄░▒█░░▀█ Written in Rust.
░█▀▀▄░▀█▀░▒█░▄▀░▒█▀▀▀░▒█▄░▒█ Modern and modular toolkit
▒█▄▄█░▒█░░▒█▀▄░░▒█▀▀▀░▒█▒█▒█ for <green><bold>Cardano</bold></green> Smart Contract development.
▒█░▒█░▄█▄░▒█░▒█░▒█▄▄▄░▒█░░▀█ Written in Rust.
================================================================================
Repo : https://github.com/aiken-lang/aiken
Docs : https://aiken-lang.org/
Chat : https://discord.gg/Vc3x8N9nz2
Contribute : https://github.com/aiken-lang/aiken/blob/main/CONTRIBUTING.md
================================================================================"#
<magenta>repo:</magenta> <blue><italic><dim>https://github.com/aiken-lang/aiken</dim></italic></blue>
<magenta>docs:</magenta> <blue><italic><dim>https://aiken-lang.org</dim></italic></blue>
<magenta>chat:</magenta> <blue><italic><dim>https://discord.gg/Vc3x8N9nz2</dim></italic></blue>
<magenta>contribute:</magenta> <blue><italic><dim>https://github.com/aiken-lang/aiken/blob/main/CONTRIBUTING.md</dim></italic></blue>"#
};

0 comments on commit 61641df

Please sign in to comment.