-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add name to code unit detectors * feat: add describe * feat: detect parent crate of rust source file
- Loading branch information
Showing
13 changed files
with
194 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::core::RingCore; | ||
use clap::{arg, value_parser, ArgMatches, Command}; | ||
use crossterm::style::Stylize; | ||
use std::env; | ||
use std::path::PathBuf; | ||
use itertools::Itertools; | ||
use tracing::instrument; | ||
use ring_tag::Tag; | ||
|
||
pub fn build_command() -> Command { | ||
Command::new("describe") | ||
.aliases(["d", "desc"]) | ||
.arg(arg!([path]) | ||
.value_parser(value_parser!(PathBuf))) | ||
} | ||
|
||
#[instrument(name = "cli.describe", skip(core, args))] | ||
pub fn handle_command(core: &RingCore, args: &ArgMatches) -> anyhow::Result<()> { | ||
// Extract arguments | ||
let current_dir = env::current_dir()?; | ||
let path = args.get_one::<PathBuf>("path") | ||
.unwrap_or(¤t_dir); | ||
|
||
for detector in core.code_unit_detectors() { | ||
if let Some(unit) = detector.detect(path)? { | ||
println!("{} detected by {}", | ||
unit.name().map(Stylize::bold).unwrap_or("unknown".dark_grey()), | ||
detector.name()); | ||
|
||
if let Some(parent) = unit.parent() { | ||
println!("\u{2570}\u{2574}{} at {}", | ||
parent.name().map(Stylize::bold).unwrap_or("unknown".dark_grey()), | ||
parent.path().display()); | ||
} | ||
|
||
println!("language: {}", Tag::from(unit.language()).stylize()); | ||
println!("tags: {}", unit.tags().iter().map(Tag::stylize_full).join(" ")); | ||
println!(); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod describe; | ||
pub mod list; | ||
pub mod processes; | ||
pub mod processes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.