diff --git a/docs/index.md b/docs/index.md index 9e44ac0d..d869c6f8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,6 +21,7 @@ - [`gm repo goto root`](nu-git-manager-sugar/git/gm-repo-goto-root.md) - [`gm repo is-ancestor`](nu-git-manager-sugar/git/gm-repo-is-ancestor.md) - [`gm repo ls`](nu-git-manager-sugar/git/gm-repo-ls.md) +- [`gm repo query`](nu-git-manager-sugar/git/gm-repo-query.md) - [`gm repo remote list`](nu-git-manager-sugar/git/gm-repo-remote-list.md) - [`gm repo switch`](nu-git-manager-sugar/git/gm-repo-switch.md) - [`setup`](nu-git-manager-sugar/git/prompt/setup.md) diff --git a/docs/nu-git-manager-sugar/git/gm-repo-ls.md b/docs/nu-git-manager-sugar/git/gm-repo-ls.md index 1b69a504..90cf2397 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-ls.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-ls.md @@ -12,6 +12,6 @@ get some information about a repo - description: the path to the repo (defaults to `.`) ## Signatures -| input | output | -| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `nothing` | `record, branch: string>` | +| input | output | +| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `nothing` | `record, unstaged: list, untracked: list, last_commit: record, branch: string>` | diff --git a/docs/nu-git-manager-sugar/git/gm-repo-query.md b/docs/nu-git-manager-sugar/git/gm-repo-query.md new file mode 100644 index 00000000..83404af3 --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-query.md @@ -0,0 +1,17 @@ +# `nu-git-manager-sugar git gm repo query` +## Description +TODO: documentation + + + +## Parameters +- parameter_name: table +- parameter_type: positional +- syntax_shape: completable +- is_optional: false +- custom_completion: git-query-tables + +## Signatures +| input | output | +| --------- | ------- | +| `nothing` | `table` | diff --git a/docs/nu-git-manager-sugar/git/index.md b/docs/nu-git-manager-sugar/git/index.md index dcba42e3..2743a3b7 100644 --- a/docs/nu-git-manager-sugar/git/index.md +++ b/docs/nu-git-manager-sugar/git/index.md @@ -12,6 +12,7 @@ - [`gm repo goto root`](gm-repo-goto-root.md) - [`gm repo is-ancestor`](gm-repo-is-ancestor.md) - [`gm repo ls`](gm-repo-ls.md) +- [`gm repo query`](gm-repo-query.md) - [`gm repo remote list`](gm-repo-remote-list.md) - [`gm repo switch`](gm-repo-switch.md) diff --git a/src/nu-git-manager-sugar/completions/nu-complete.nu b/src/nu-git-manager-sugar/completions/nu-complete.nu new file mode 100644 index 00000000..6311a5a9 --- /dev/null +++ b/src/nu-git-manager-sugar/completions/nu-complete.nu @@ -0,0 +1,5 @@ +export const GIT_QUERY_TABLES = ["refs", "commits", "diffs", "branches", "tags"] + +export def git-query-tables []: nothing -> list { + $GIT_QUERY_TABLES +} diff --git a/src/nu-git-manager-sugar/git/mod.nu b/src/nu-git-manager-sugar/git/mod.nu index 45069737..a0d2de51 100644 --- a/src/nu-git-manager-sugar/git/mod.nu +++ b/src/nu-git-manager-sugar/git/mod.nu @@ -2,6 +2,8 @@ use std log use ../git/lib/lib.nu [get-status] +use ../completions/nu-complete.nu [GIT_QUERY_TABLES, git-query-tables] + # get the commit hash of any revision # # # Examples @@ -257,3 +259,33 @@ export def "gm repo ls" [ branch: (^git -C $repo branch --show-current), } } + +# TODO: documentation +export def "gm repo query" [table: string@git-query-tables]: nothing -> table { + if $table not-in $GIT_QUERY_TABLES { + error make { + msg: $"(ansi red_bold)invalid_qit_query_table(ansi reset)", + label: { + text: $"expected one of ($GIT_QUERY_TABLES), got '($table)'" + span: (metadata $table).span, + } + } + } + + if (which "query git" | is-empty) { + error make --unspanned { + msg: ( + $"(ansi red_bold)requirement_not_found(ansi reset):\n" + + $"could not find `(ansi default_dimmed)query git(ansi reset)` in current scope\n" + + "\n" + + $"(ansi cyan)help(ansi reset): install the (ansi blue_dimmed)[`(ansi reset)(ansi blue_bold)nu_plugin_query_git(ansi reset)(ansi blue_dimmed)`]\(https://github.com/fdncred/nu_plugin_query_git\)(ansi reset) plugin with `(ansi default_dimmed)cargo build --release(ansi reset)` and then `(ansi default_dimmed)register(ansi reset)` it" + ) + } + } + + if $table == "commits" { + query git $"select * from commits" | into datetime datetime + } else { + query git $"select * from ($table)" + } +} diff --git a/tests/sugar/mod.nu b/tests/sugar/mod.nu index 20dbe9a5..fed29e15 100644 --- a/tests/sugar/mod.nu +++ b/tests/sugar/mod.nu @@ -20,6 +20,7 @@ export module imports { "gm repo goto root", "gm repo is-ancestor", "gm repo ls", + "gm repo query", "gm repo remote list", "gm repo switch", "prompt setup",