Skip to content

Commit

Permalink
feat: add skeleton for search command
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jan 16, 2024
1 parent c7f7825 commit 8b047c1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions rocks-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.17", features = ["derive"] }
nucleo-matcher = "0.3.0"
text_trees = "0.1.2"
17 changes: 15 additions & 2 deletions rocks-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::path::PathBuf;

use clap::{Parser, Subcommand};

mod search;

/// An small and efficient Lua package manager.
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
Expand Down Expand Up @@ -99,7 +102,7 @@ enum Commands {
/// Uninstall a rock.
Remove,
/// Query the Luarocks servers.
Search,
Search(search::Search),
/// Show information about an installed rock.
Show,
/// Run the test suite in the current directory.
Expand All @@ -115,5 +118,15 @@ enum Commands {
}

fn main() {
let _cli = Cli::parse();
let cli = Cli::parse();

match cli.command {
Some(command) => match command {
Commands::Search(search_data) => search::search(search_data).unwrap(),
_ => unimplemented!(),
},
None => {
println!("TODO: Display configuration information here. Consider supplying a command instead.");
}
}
}
23 changes: 23 additions & 0 deletions rocks-bin/src/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anyhow::Result;
use clap::Args;
use text_trees::{StringTreeNode, FormatCharacters, TreeFormatting};

#[derive(Args)]
pub struct Search {
/// Name of the rock to search for.
name: String,
/// Rocks version to search for.
version: Option<String>,

// TODO(vhyrro): Add options.
}

pub fn search(data: Search) -> Result<()> {
let mut tree = StringTreeNode::new("Root Manifest".into());

tree.push("Something cool".into());

println!("{}", tree.to_string_with_format(&TreeFormatting::dir_tree(FormatCharacters::box_chars()))?);

Ok(())
}

0 comments on commit 8b047c1

Please sign in to comment.