Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed Dec 20, 2024
1 parent e11c19c commit 5194eca
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
26 changes: 26 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
31 changes: 23 additions & 8 deletions src/model/just/just.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -9,18 +9,28 @@ pub struct Just {
}
impl Just {
// TODO: add new
pub(crate) fn to_commands(&self) -> Vec<command::Command> {
pub fn new(current_dir: PathBuf) -> Result<Just> {
// 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<command::Command> {
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<String, anyhow::Error> {
pub fn command_to_run(&self, command: &command::Command) -> Result<String, anyhow::Error> {
let command = match self.get_command(command.clone()) {
Some(c) => c,
None => return Err(anyhow!("command not found")),
Expand All @@ -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")),
Expand All @@ -55,4 +65,9 @@ impl Just {
.find(|c| **c == command)
.map(|_| command)
}

fn find_justfile(current_dir: PathBuf) -> Result<PathBuf> {
// current_dirの親ディレクトリを取得
// justfileが見つかるまで子 -> 親方向に走査
}
}
2 changes: 2 additions & 0 deletions src/usecase/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -374,6 +375,7 @@ impl SelectCommandState<'_> {
CurrentPane::Main
};

just::Just::new(current_dir.clone());
let runners = {
let mut runners = vec![];

Expand Down

0 comments on commit 5194eca

Please sign in to comment.