Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gm repo query #127

Merged
merged 8 commits into from
Dec 13, 2023
Merged
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
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions docs/nu-git-manager-sugar/git/gm-repo-ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ get some information about a repo
- description: the path to the repo (defaults to `.`)

## Signatures
| input | output |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `nothing` | `record<path: string, name: string, staged: int, unstaged: int, untracked: int, last_commit: record<date: datetime, title: string, hash: string>, branch: string>` |
| input | output |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nothing` | `record<path: string, name: string, staged: list<string>, unstaged: list<string>, untracked: list<string>, last_commit: record<date: datetime, title: string, hash: string>, branch: string>` |
17 changes: 17 additions & 0 deletions docs/nu-git-manager-sugar/git/gm-repo-query.md
Original file line number Diff line number Diff line change
@@ -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<string>
- is_optional: false
- custom_completion: git-query-tables

## Signatures
| input | output |
| --------- | ------- |
| `nothing` | `table` |
1 change: 1 addition & 0 deletions docs/nu-git-manager-sugar/git/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions src/nu-git-manager-sugar/completions/nu-complete.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const GIT_QUERY_TABLES = ["refs", "commits", "diffs", "branches", "tags"]

export def git-query-tables []: nothing -> list<string> {
$GIT_QUERY_TABLES
}
32 changes: 32 additions & 0 deletions src/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
}
}
1 change: 1 addition & 0 deletions tests/sugar/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down