Skip to content

feat: add non-interactive mode with auto TTY detection#8

Open
zhanba wants to merge 1 commit intomainfrom
feat/interactive-and-non-interactive-mode
Open

feat: add non-interactive mode with auto TTY detection#8
zhanba wants to merge 1 commit intomainfrom
feat/interactive-and-non-interactive-mode

Conversation

@zhanba
Copy link
Copy Markdown
Owner

@zhanba zhanba commented Mar 13, 2026

Summary

  • Add global -n/--no-interactive and -y/--yes CLI flags that apply to every subcommand
  • Auto-detect non-interactive mode via is-terminal crate (triggers automatically in pipes/CI/scripts)
  • find_repo() / select_worktree() now filter by query string in non-interactive mode, exiting 1 with actionable errors on zero/ambiguous matches
  • exec_into_dir() prints the resolved path to stdout in non-interactive mode, enabling cd $(pji -n find myrepo) shell integration
  • confirm() returns --yes flag value instead of prompting in non-interactive mode
  • config gains --root <path> flag; worktree add gains --branch, --new-branch, --base, --path flags

New CLI usage

# Interactive (default in terminal) — unchanged behaviour
pji myrepo
pji worktree add

# Non-interactive (auto-detected in pipes/CI, or explicit -n)
pji -n find myrepo               # prints path, exits 0
cd $(pji -n find myrepo)         # cd shell integration
pji -n find myrepo | xargs code  # open in editor

pji config --root ~/projects     # add root without TUI
pji -n -y remove git@github.com:org/repo.git  # skip confirmation

pji -n worktree add --branch feat/x --new-branch --base main
pji -n worktree switch feat/x
pji -n worktree remove feat/x

Test plan

  • Run pji myrepo in a terminal — fuzzy TUI still appears as before
  • Run pji -n find myrepo — prints the repo path and exits
  • Run cd $(pji -n find myrepo) — changes directory successfully
  • Run pji -n find ambiguous with multiple matches — exits 1 with list
  • Run pji -n find nomatch — exits 1 with clear error message
  • Run echo "" | pji find myrepo — auto-detects non-TTY, prints path
  • Run pji config --root ~/projects — adds root without interactive prompt
  • Run pji -n worktree add --branch feat/x --new-branch — creates worktree without TUI
  • Run pji -n -y worktree remove feat/x — removes without confirmation

🤖 Generated with Pochi | Task

- Add `is_interactive_mode()` to util.rs using `is-terminal` crate for
  zero-cost TTY detection (auto-detects pipes/CI environments)
- Add global `-n/--no-interactive` and `-y/--yes` CLI flags to all commands
- `PjiApp::new(interactive, auto_yes)` replaces no-arg constructor; mode
  is threaded through all selection and confirmation methods
- `find_repo()`: interactive shows fuzzy TUI; non-interactive filters by
  query string and exits 1 with clear error on zero/ambiguous matches
- `exec_into_dir()`: interactive replaces process with shell; non-interactive
  prints path to stdout enabling `cd $(pji -n find myrepo)` integration
- `confirm()`: non-interactive returns `auto_yes` value instead of prompting
- `config` gains `--root <path>` flag for non-interactive root setup
- `worktree add` gains `--branch`, `--new-branch`, `--base`, `--path` flags
- `worktree remove` requires worktree arg in non-interactive mode
- `worktree switch/select_worktree`: filter by query, error on ambiguity

🤖 Generated with [Pochi](https://getpochi.com) | [Task](https://app.getpochi.com/share/p-91a6df75e9964bc4bff2f60476413412)

Co-Authored-By: Pochi <noreply@getpochi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant