Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Args {
pub enum Subcommand {
Run(RunCommand),
Init(InitCommand),
List(ListCommand),
}

#[derive(FromArgs, PartialEq, Debug)]
Expand All @@ -27,13 +28,31 @@ pub struct RunCommand {
/// sort by deadline (default: false)
#[argh(switch)]
pub sort_by_deadline: Option<bool>,
// search path (default: search directry written in config file)
#[argh(positional)]
pub search_path: Option<String>,
}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "init")]
/// initialize a config of reminder-lint
pub struct InitCommand {}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "list")]
/// list reminder-lint comments
pub struct ListCommand {
/// path to the config file (default: ./remind.yml)
#[argh(option, short = 'c')]
pub config_file_path: Option<String>,
/// path to the ignore file (default: ./.remindignore)
#[argh(option, short = 'i')]
pub ignore_file_path: Option<String>,
// search path (default: search directry written in config file)
#[argh(positional)]
pub search_path: Option<String>,
}

impl Args {
pub fn new() -> Self {
argh::from_env()
Expand Down
28 changes: 28 additions & 0 deletions cli/src/subcommand/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::args::ListCommand;
use anyhow::Error;
use reminder_lint_core::config::builder::ConfigBuilder;

pub fn execute_list(command: ListCommand) -> Result<(), Error> {
let conf = ConfigBuilder::new()
.config_file_path(command.config_file_path)
.ignore_file_path(command.ignore_file_path)
.build()?;

let reminders = reminder_lint_core::reminders(&conf, command.search_path)?;
Comment on lines +6 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

We can pass the search path option with ConfigBuilder, then passed, it can be merged into Config. 🤔
Anything you intended?


for remind in &reminders.expired {
println!(
"{}:{} {}",
remind.position.file, remind.position.line, remind.message
);
}

for remind in &reminders.upcoming {
println!(
"{}:{} {}",
remind.position.file, remind.position.line, remind.message
);
}

Ok(())
}
4 changes: 3 additions & 1 deletion cli/src/subcommand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ use crate::{
print::{pretty_print, Status},
};

use self::{init::execute_init, run::execute_run};
use self::{init::execute_init, list::execute_list, run::execute_run};

mod init;
mod list;
mod run;

pub fn execute_subcommand(subcommand: Subcommand) {
let result = match subcommand {
Subcommand::Run(command) => execute_run(command),
Subcommand::Init(command) => execute_init(command),
Subcommand::List(command) => execute_list(command),
};

if let Err(e) = result {
Expand Down
3 changes: 2 additions & 1 deletion cli/src/subcommand/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub fn execute_run(command: RunCommand) -> Result<(), Error> {
.sort_by_deadline(command.sort_by_deadline)
.build()?;

let reminders = reminder_lint_core::reminders(&conf)?;
let reminders = reminder_lint_core::reminders(&conf, command.search_path)?;

for remind in &reminders.expired {
println!(
"{}:{} {}",
Expand Down
7 changes: 5 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ pub struct Reminders {
pub upcoming: Vec<remind::Remind>,
}

pub fn reminders(conf: &Config) -> Result<Reminders, ReminderLintError> {
let reminders = list_reminders(&conf).map_err(|e| ReminderLintError::from(e))?;
pub fn reminders(
conf: &Config,
search_path: Option<String>,
) -> Result<Reminders, ReminderLintError> {
let reminders = list_reminders(&conf, search_path).map_err(|e| ReminderLintError::from(e))?;

let mut expired = Vec::new();
let mut upcoming = Vec::new();
Expand Down
7 changes: 5 additions & 2 deletions core/src/remind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Position {
pub line: u64,
}

pub fn list_reminders(config: &Config) -> Result<Vec<Remind>, Error> {
pub fn list_reminders(config: &Config, target: Option<String>) -> Result<Vec<Remind>, Error> {
let meta_regex = convert_meta_regex(&config.comment_regex());
let matcher = RegexMatcherBuilder::new().build(&meta_regex)?;

Expand All @@ -37,7 +37,10 @@ pub fn list_reminders(config: &Config) -> Result<Vec<Remind>, Error> {
.line_number(true)
.build();

let mut builder = WalkBuilder::new(&config.search_directory());
let mut builder = match target {
Some(t) => WalkBuilder::new(&t),
None => WalkBuilder::new(config.search_directory()),
};
let walker = builder
.hidden(false)
.add_custom_ignore_filename(&config.ignore_file_path())
Expand Down