mirror of
https://github.com/onyx-and-iris/ignr.git
synced 2026-04-18 07:13:33 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f4ddb45fd2 | |||
| cad1585975 | |||
| 4139c4b291 | |||
| 856da5cd04 | |||
| a6fb3c69c7 | |||
| cf93198462 | |||
| e1875fb894 | |||
| e1b879f54c | |||
| f51302a945 | |||
| 11fe797f3f | |||
| 5b389aa9dc | |||
| bb535f296d | |||
| 5eccfc939c | |||
| 00638a6bf4 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
# Generated by ignr-cli: github.com/onyx-and-iris/ignr-cli
|
# Generated by ignr: github.com/onyx-and-iris/ignr
|
||||||
|
|
||||||
## Go ##
|
## Go ##
|
||||||
# If you prefer the allow list template instead of the deny list, see community template:
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
@@ -36,4 +36,4 @@ go.work.sum
|
|||||||
# .idea/
|
# .idea/
|
||||||
# .vscode/
|
# .vscode/
|
||||||
|
|
||||||
# End of ignr-cli
|
# End of ignr
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -2,7 +2,7 @@
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
# ignr-cli
|
# ignr
|
||||||
|
|
||||||
Simple no-frills .gitignore generator backed by the Github API.
|
Simple no-frills .gitignore generator backed by the Github API.
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ Simple no-frills .gitignore generator backed by the Github API.
|
|||||||
## Install
|
## Install
|
||||||
|
|
||||||
```console
|
```console
|
||||||
go install github.com/onyx-and-iris/ignr-cli@latest
|
go install github.com/onyx-and-iris/ignr@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@@ -20,9 +20,10 @@ go install github.com/onyx-and-iris/ignr-cli@latest
|
|||||||
|
|
||||||
- --token/-t: GitHub authentication token
|
- --token/-t: GitHub authentication token
|
||||||
- note, this tool can be used **without** authenticating but rate limiting will be stricter.
|
- note, this tool can be used **without** authenticating but rate limiting will be stricter.
|
||||||
- --height/-H: Height of the selection prompt (default 20)
|
- --height/-H: Height of the selection prompt (default 10)
|
||||||
- --filter/-f: Type of filter to apply to the list of templates (default startswith)
|
- --filter/-f: Type of filter to apply to the list of templates (default startswith)
|
||||||
- may be one of (startswith, contains)
|
- may be one of (startswith, contains)
|
||||||
|
- --start-search/-s: Start the prompt in search mode (default false)
|
||||||
|
|
||||||
*environment variables*
|
*environment variables*
|
||||||
|
|
||||||
@@ -30,8 +31,9 @@ go install github.com/onyx-and-iris/ignr-cli@latest
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
export IGNR_TOKEN=<API Token>
|
export IGNR_TOKEN=<API Token>
|
||||||
export IGNR_HEIGHT=20
|
export IGNR_HEIGHT=10
|
||||||
export IGNR_FILTER=startswith
|
export IGNR_FILTER=startswith
|
||||||
|
export IGNR_START_SEARCH=false
|
||||||
```
|
```
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
@@ -41,13 +43,14 @@ export IGNR_FILTER=startswith
|
|||||||
Trigger the selection prompt.
|
Trigger the selection prompt.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
ignr-cli new
|
ignr new
|
||||||
```
|
```
|
||||||
|
|
||||||
The prompt filter can be activated by pressing `/`:
|
Search mode can be activated by pressing `/`:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Special Thanks
|
## Special Thanks
|
||||||
|
|
||||||
- [Charm](https://github.com/charmbracelet) for their awesome CLI packages.
|
- [spf13](https://github.com/spf13) for the [cobra](https://github.com/spf13/cobra) and [viper](https://github.com/spf13/viper) packages.
|
||||||
|
- [Manifold](https://github.com/manifoldco) for the [promptui](https://github.com/manifoldco/promptui) package.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
PROGRAM: ignr-cli
|
PROGRAM: ignr
|
||||||
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
|
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
|
||||||
BIN_DIR: bin
|
BIN_DIR: bin
|
||||||
VERSION:
|
VERSION:
|
||||||
@@ -12,12 +12,12 @@ vars:
|
|||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
desc: Build the ignr-cli project
|
desc: Build the ignr project
|
||||||
cmds:
|
cmds:
|
||||||
- task: build
|
- task: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
desc: Build the ignr-cli project
|
desc: Build the ignr project
|
||||||
deps: [vet]
|
deps: [vet]
|
||||||
cmds:
|
cmds:
|
||||||
- task: build-windows
|
- task: build-windows
|
||||||
@@ -35,13 +35,13 @@ tasks:
|
|||||||
- go fmt ./...
|
- go fmt ./...
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
desc: Build the ignr-cli project for Windows
|
desc: Build the ignr project for Windows
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}"
|
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}"
|
||||||
internal: true
|
internal: true
|
||||||
|
|
||||||
build-linux:
|
build-linux:
|
||||||
desc: Build the ignr-cli project for Linux
|
desc: Build the ignr project for Linux
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
||||||
internal: true
|
internal: true
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// filterFunc returns a function that filters templates based on the specified filter type.
|
// filterFunc returns a function that filters templates based on the specified filter type.
|
||||||
func filterFunc(templates []string) func(input string, index int) bool {
|
func filterFunc(templates []string, filterType string) func(input string, index int) bool {
|
||||||
switch viper.GetString("filter") {
|
switch filterType {
|
||||||
case "contains":
|
case "contains":
|
||||||
return func(input string, index int) bool {
|
return func(input string, index int) bool {
|
||||||
return strings.Contains(strings.ToLower(templates[index]), strings.ToLower(input))
|
return strings.Contains(strings.ToLower(templates[index]), strings.ToLower(input))
|
||||||
|
|||||||
20
go.mod
20
go.mod
@@ -1,8 +1,9 @@
|
|||||||
module github.com/onyx-and-iris/ignr-cli
|
module github.com/onyx-and-iris/ignr
|
||||||
|
|
||||||
go 1.24.3
|
go 1.24.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/charmbracelet/fang v0.1.0
|
||||||
github.com/google/go-github/v72 v72.0.0
|
github.com/google/go-github/v72 v72.0.0
|
||||||
github.com/manifoldco/promptui v0.9.0
|
github.com/manifoldco/promptui v0.9.0
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
@@ -10,21 +11,36 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/charmbracelet/colorprofile v0.3.0 // indirect
|
||||||
|
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 // indirect
|
||||||
|
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
||||||
|
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
|
||||||
|
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 // indirect
|
||||||
|
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
|
github.com/muesli/mango v0.1.0 // indirect
|
||||||
|
github.com/muesli/mango-cobra v1.2.0 // indirect
|
||||||
|
github.com/muesli/mango-pflag v0.1.0 // indirect
|
||||||
|
github.com/muesli/roff v0.1.0 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.12.0 // indirect
|
github.com/spf13/afero v1.12.0 // indirect
|
||||||
github.com/spf13/cast v1.7.1 // indirect
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
github.com/spf13/pflag v1.0.6 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/sys v0.31.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
golang.org/x/text v0.23.0 // indirect
|
golang.org/x/text v0.24.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
43
go.sum
43
go.sum
@@ -1,3 +1,21 @@
|
|||||||
|
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||||
|
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||||
|
github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ=
|
||||||
|
github.com/charmbracelet/colorprofile v0.3.0/go.mod h1:oHJ340RS2nmG1zRGPmhJKJ/jf4FPNNk0P39/wBPA1G0=
|
||||||
|
github.com/charmbracelet/fang v0.1.0 h1:SlZS2crf3/zQh7Mr4+W+7QR1k+L08rrPX5rm5z3d7Wg=
|
||||||
|
github.com/charmbracelet/fang v0.1.0/go.mod h1:Zl/zeUQ8EtQuGyiV0ZKZlZPDowKRTzu8s/367EpN/fc=
|
||||||
|
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 h1:D9AJJuYTN5pvz6mpIGO1ijLKpfTYSHOtKGgwoTQ4Gog=
|
||||||
|
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1/go.mod h1:tRlx/Hu0lo/j9viunCN2H+Ze6JrmdjQlXUQvvArgaOc=
|
||||||
|
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
||||||
|
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
||||||
|
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
|
||||||
|
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||||
|
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 h1:IJDiTgVE56gkAGfq0lBEloWgkXMk4hl/bmuPoicI4R0=
|
||||||
|
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0=
|
||||||
|
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a h1:G99klV19u0QnhiizODirwVksQB91TJKV/UaTnACcG30=
|
||||||
|
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||||
|
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||||
|
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
|
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
||||||
@@ -27,12 +45,29 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
|||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
||||||
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
|
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||||
|
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||||
|
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
|
||||||
|
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
|
||||||
|
github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg=
|
||||||
|
github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA=
|
||||||
|
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
|
||||||
|
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
|
||||||
|
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
|
||||||
|
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
@@ -56,15 +91,19 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
|
|||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||||
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||||
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||||
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 10 KiB |
52
main.go
52
main.go
@@ -3,12 +3,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"os"
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/fang"
|
||||||
"github.com/google/go-github/v72/github"
|
"github.com/google/go-github/v72/github"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@@ -18,9 +17,9 @@ var version string // Version of the CLI, set during build time
|
|||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands.
|
// rootCmd represents the base command when called without any subcommands.
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "ignr-cli",
|
Use: "ignr",
|
||||||
Short: "A command-line interface for generating .gitignore files",
|
Short: "A command-line interface for generating .gitignore files",
|
||||||
Long: `ignr-cli is a command-line interface for generating .gitignore files.
|
Long: `ignr is a command-line interface for generating .gitignore files.
|
||||||
It allows users to easily create and manage .gitignore files for various programming languages and frameworks.
|
It allows users to easily create and manage .gitignore files for various programming languages and frameworks.
|
||||||
You may also list available templates and generate .gitignore files based on those templates.`,
|
You may also list available templates and generate .gitignore files based on those templates.`,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
@@ -31,47 +30,46 @@ You may also list available templates and generate .gitignore files based on tho
|
|||||||
} else {
|
} else {
|
||||||
client = github.NewClient(nil).WithAuthToken(viper.GetString("token"))
|
client = github.NewClient(nil).WithAuthToken(viper.GetString("token"))
|
||||||
}
|
}
|
||||||
ctx := withClient(context.Background(), client)
|
ctx := withClient(cmd.Context(), client)
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
//RunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
if cmd.Flags().Lookup("version").Changed {
|
//},
|
||||||
if version == "" {
|
|
||||||
info, ok := debug.ReadBuildInfo()
|
|
||||||
if !ok {
|
|
||||||
return errors.New("unable to retrieve build information")
|
|
||||||
}
|
|
||||||
version = strings.Split(info.Main.Version, "-")[0]
|
|
||||||
}
|
|
||||||
fmt.Printf("ignr-cli version: %s\n", version)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd.Help()
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init initialises the root command and its flags.
|
// init initialises the root command and its flags.
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().StringP("token", "t", "", "GitHub authentication token")
|
rootCmd.PersistentFlags().StringP("token", "t", "", "GitHub authentication token")
|
||||||
rootCmd.PersistentFlags().IntP("height", "H", 20, "Height of the selection prompt")
|
rootCmd.PersistentFlags().IntP("height", "H", 10, "Height of the selection prompt")
|
||||||
rootCmd.PersistentFlags().
|
rootCmd.PersistentFlags().
|
||||||
StringP("filter", "f", "startswith", "Type of filter to apply to the list of templates (e.g., 'startswith', 'contains')")
|
StringP("filter", "f", "startswith", "Type of filter to apply to the list of templates (e.g., 'startswith', 'contains')")
|
||||||
|
rootCmd.PersistentFlags().BoolP("start-search", "s", false, "Start the prompt in search mode")
|
||||||
|
|
||||||
rootCmd.Flags().BoolP("version", "v", false, "Print the version of the CLI")
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||||
|
|
||||||
viper.SetEnvPrefix("IGNR")
|
viper.SetEnvPrefix("IGNR")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))
|
viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))
|
||||||
viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height"))
|
viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height"))
|
||||||
viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter"))
|
viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter"))
|
||||||
|
viper.BindPFlag("start-search", rootCmd.PersistentFlags().Lookup("start-search"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// main is the entry point of the application.
|
// main is the entry point of the application.
|
||||||
// It executes the root command and handles any errors.
|
// It executes the root command and handles any errors.
|
||||||
func main() {
|
func main() {
|
||||||
err := rootCmd.Execute()
|
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(versionFromBuild())); err != nil {
|
||||||
if err != nil {
|
os.Exit(1)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func versionFromBuild() string {
|
||||||
|
if version == "" {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return "(unable to read version)"
|
||||||
|
}
|
||||||
|
version = strings.Split(info.Main.Version, "-")[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|||||||
37
new.go
37
new.go
@@ -29,11 +29,21 @@ func init() {
|
|||||||
rootCmd.AddCommand(newCmd)
|
rootCmd.AddCommand(newCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type promptConfig struct {
|
||||||
|
Height int
|
||||||
|
StartSearch bool
|
||||||
|
FilterType string
|
||||||
|
}
|
||||||
|
|
||||||
// runNewCommand is the handler for the 'new' command.
|
// runNewCommand is the handler for the 'new' command.
|
||||||
// It retrieves the selected .gitignore template from GitHub and writes it to the .gitignore file.
|
// It retrieves the selected .gitignore template from GitHub and writes it to the .gitignore file.
|
||||||
func runNewCommand(cmd *cobra.Command, _ []string) error {
|
func runNewCommand(cmd *cobra.Command, _ []string) error {
|
||||||
height := viper.GetInt("height")
|
pc := promptConfig{
|
||||||
if height <= 0 {
|
Height: viper.GetInt("height"),
|
||||||
|
StartSearch: viper.GetBool("start-search"),
|
||||||
|
FilterType: viper.GetString("filter"),
|
||||||
|
}
|
||||||
|
if pc.Height <= 0 {
|
||||||
return errors.New("height must be a positive integer")
|
return errors.New("height must be a positive integer")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +52,7 @@ func runNewCommand(cmd *cobra.Command, _ []string) error {
|
|||||||
return errors.New("failed to get GitHub client from context")
|
return errors.New("failed to get GitHub client from context")
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := runPrompt(client, height)
|
content, err := runPrompt(client, &pc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error running selection prompt: %w", err)
|
return fmt.Errorf("error running selection prompt: %w", err)
|
||||||
}
|
}
|
||||||
@@ -61,13 +71,13 @@ func runNewCommand(cmd *cobra.Command, _ []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// runPrompt is a helper function to run the selection prompt for .gitignore templates.
|
// runPrompt is a helper function to run the selection prompt for .gitignore templates.
|
||||||
func runPrompt(client *github.Client, height int) (*github.Gitignore, error) {
|
func runPrompt(client *github.Client, pc *promptConfig) (*github.Gitignore, error) {
|
||||||
templates, _, err := client.Gitignores.List(context.Background())
|
templates, _, err := client.Gitignores.List(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error retrieving gitignore template list: %w", err)
|
return nil, fmt.Errorf("error retrieving gitignore template list: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
selectTemmplates := &promptui.SelectTemplates{
|
selectTemplates := &promptui.SelectTemplates{
|
||||||
Label: ` {{ "\U0000007C" | faint }} {{ . | magenta | bold }}`,
|
Label: ` {{ "\U0000007C" | faint }} {{ . | magenta | bold }}`,
|
||||||
Active: `{{ "\U0000007C" | faint }} {{ "🌶" | red }} {{ . | cyan | italic }}`,
|
Active: `{{ "\U0000007C" | faint }} {{ "🌶" | red }} {{ . | cyan | italic }}`,
|
||||||
Inactive: `{{ "\U0000007C" | faint }} {{ . | faint }}`,
|
Inactive: `{{ "\U0000007C" | faint }} {{ . | faint }}`,
|
||||||
@@ -75,16 +85,17 @@ func runPrompt(client *github.Client, height int) (*github.Gitignore, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prompt := promptui.Select{
|
prompt := promptui.Select{
|
||||||
Label: "Select a .gitignore template",
|
Label: "Select a .gitignore template",
|
||||||
Items: templates,
|
Items: templates,
|
||||||
Templates: selectTemmplates,
|
Templates: selectTemplates,
|
||||||
Size: height,
|
Size: pc.Height,
|
||||||
Searcher: filterFunc(templates),
|
Searcher: filterFunc(templates, pc.FilterType),
|
||||||
|
StartInSearchMode: pc.StartSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
i, _, err := prompt.Run()
|
i, _, err := prompt.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error running selection prompt: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
content, _, err := client.Gitignores.Get(context.Background(), templates[i])
|
content, _, err := client.Gitignores.Get(context.Background(), templates[i])
|
||||||
@@ -97,7 +108,7 @@ func runPrompt(client *github.Client, height int) (*github.Gitignore, error) {
|
|||||||
|
|
||||||
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
||||||
func commitGitignore(content *github.Gitignore, w io.Writer) error {
|
func commitGitignore(content *github.Gitignore, w io.Writer) error {
|
||||||
if _, err := fmt.Fprintf(w, "# Generated by ignr-cli: github.com/onyx-and-iris/ignr-cli\n\n## %s ##\n", content.GetName()); err != nil {
|
if _, err := fmt.Fprintf(w, "# Generated by ignr: github.com/onyx-and-iris/ignr\n\n## %s ##\n", content.GetName()); err != nil {
|
||||||
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +116,7 @@ func commitGitignore(content *github.Gitignore, w io.Writer) error {
|
|||||||
return fmt.Errorf("error writing to file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error writing to file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprintf(w, "\n# End of ignr-cli\n"); err != nil {
|
if _, err := fmt.Fprintf(w, "\n# End of ignr\n"); err != nil {
|
||||||
return fmt.Errorf("error writing footer to file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error writing footer to file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user