From 5194ecaa6e77b5facac5017ebeb371417707d751 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Tue, 17 Dec 2024 22:56:17 +0900 Subject: [PATCH] wip --- justfile | 26 ++++++++++++++++++++++++++ src/model/just/just.rs | 31 +++++++++++++++++++++++-------- src/usecase/tui/app.rs | 2 ++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 00000000..1be10022 --- /dev/null +++ b/justfile @@ -0,0 +1,26 @@ +#!/usr/bin/env -S just --justfile + +test: + cargo test --all + +[group: 'misc'] +run: + cargo run + +[group: 'misc'] +build: + cargo build + +[group: 'misc'] +fmt: + cargo fmt --all + +[group: 'misc'] +[private] +fmt-private: + cargo fmt --all + +# everyone's favorite animate paper clip +[group: 'check'] +clippy: + cargo clippy --all --all-targets --all-features -- --deny warnings diff --git a/src/model/just/just.rs b/src/model/just/just.rs index bcda5d5f..f1f22a84 100644 --- a/src/model/just/just.rs +++ b/src/model/just/just.rs @@ -1,5 +1,5 @@ use crate::model::command; -use anyhow::anyhow; +use anyhow::{anyhow, bail, Result}; use std::{path::PathBuf, process}; #[derive(Debug, Clone, PartialEq)] @@ -9,18 +9,28 @@ pub struct Just { } impl Just { // TODO: add new - pub(crate) fn to_commands(&self) -> Vec { + pub fn new(current_dir: PathBuf) -> Result { + // TODO: justではjustfileの子ディレクトリでもjust testのように実行できる。 + // 子ディレクトリでもfzf-makeを実行できるためにはjustfileのパスを取得する必要がある。 + // 現状justコマンドでこれをする方法が見つからなかったため、親方向にgit rootまで調べるくらいしか方法がないかもしれない。(git管理されてなかったらエラーにする) + // + // あとはひとまずjustfileが存在するディレクトリでの実行だけをサポートして、それから子ディレクトリでの実行をサポートするという手があるかも知れない。 + // + // just --dumpでjustfileの内容を取得 + // tree-sitterを使ってパースしつつ行番号を取得 + // tmp_fileに保存してそのpathをcommandに格納する + bail!("not implemented") + } + + pub fn to_commands(&self) -> Vec { self.commands.clone() } - pub(crate) fn path(&self) -> PathBuf { + pub fn path(&self) -> PathBuf { self.path.clone() } - pub(crate) fn command_to_run( - &self, - command: &command::Command, - ) -> Result { + pub fn command_to_run(&self, command: &command::Command) -> Result { let command = match self.get_command(command.clone()) { Some(c) => c, None => return Err(anyhow!("command not found")), @@ -29,7 +39,7 @@ impl Just { Ok(format!("just {}", command.args)) } - pub(crate) fn execute(&self, command: &command::Command) -> Result<(), anyhow::Error> { + pub fn execute(&self, command: &command::Command) -> Result<(), anyhow::Error> { let command = match self.get_command(command.clone()) { Some(c) => c, None => return Err(anyhow!("command not found")), @@ -55,4 +65,9 @@ impl Just { .find(|c| **c == command) .map(|_| command) } + + fn find_justfile(current_dir: PathBuf) -> Result { + // current_dirの親ディレクトリを取得 + // justfileが見つかるまで子 -> 親方向に走査 + } } diff --git a/src/usecase/tui/app.rs b/src/usecase/tui/app.rs index 6be49583..3974a3c0 100644 --- a/src/usecase/tui/app.rs +++ b/src/usecase/tui/app.rs @@ -6,6 +6,7 @@ use crate::{ command, histories::{self}, js_package_manager::js_package_manager_main as js, + just::just, make::make_main, runner, runner_type, }, @@ -374,6 +375,7 @@ impl SelectCommandState<'_> { CurrentPane::Main }; + just::Just::new(current_dir.clone()); let runners = { let mut runners = vec![];