3 Commits

Author SHA1 Message Date
39f762c0e6 make height a persistent flag
make a viper binding for it

env var prefix now IGNR_
2025-06-17 20:53:49 +01:00
4b756ee2fd move file 2025-06-17 20:13:40 +01:00
04e6b0ca49 add update-go-modules workflow 2025-06-17 13:36:36 +01:00
5 changed files with 47 additions and 20 deletions

30
.github/workflows/update-go-modules.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Auto-Update Go Modules
on:
schedule:
- cron: '0 0 * * 1' # Runs every Monday at midnight
jobs:
update-go-modules:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Update Dependencies
run: |
go get -u ./...
go mod tidy
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add go.mod go.sum
git commit -m "chore: auto-update Go modules"
git push

1
.gitignore vendored
View File

@@ -30,6 +30,7 @@ go.work.sum
# env file # env file
.env .env
.envrc
# Editor/IDE # Editor/IDE
# .idea/ # .idea/

View File

@@ -14,22 +14,21 @@ Simple no-frills .gitignore generator backed by the Github API.
go install github.com/onyx-and-iris/ignr-cli@latest go install github.com/onyx-and-iris/ignr-cli@latest
``` ```
## Authentication ## Configuration
You can run this tool without authenticating but requests will have a stricter rate limiting. *flags*
If you prefer to authenticate you can pass a token in the following ways: - --token/-t: GitHub authentication token
- note, this tool can be used **without** authenticating but rate limiting will be stricter.
- --height/-H: Height of the selection prompt (default 20)
*Flag* *environment variables*
- --token/-t: Github API Token
*Environment Variable*
```bash ```bash
#!/usr/bin/env bash #!/usr/bin/env bash
export GH_TOKEN=<API Token> export IGNR_TOKEN=<API Token>
export IGNR_HEIGHT=20
``` ```
## Commands ## Commands
@@ -38,11 +37,6 @@ export GH_TOKEN=<API Token>
Trigger the selection prompt. Trigger the selection prompt.
- flags:
*optional*
- --height: Height of the selection prompt, defaults to 20.
```console ```console
ignr-cli new ignr-cli new
``` ```

View File

@@ -54,11 +54,14 @@ You may also list available templates and generate .gitignore files based on tho
// 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.Flags().BoolP("version", "v", false, "Print the version of the CLI") rootCmd.Flags().BoolP("version", "v", false, "Print the version of the CLI")
viper.SetEnvPrefix("GH") 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"))
} }
// main is the entry point of the application. // main is the entry point of the application.

9
new.go
View File

@@ -11,6 +11,7 @@ import (
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"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"
) )
const gitignoreFileName = ".gitignore" const gitignoreFileName = ".gitignore"
@@ -27,16 +28,14 @@ var newCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(newCmd) rootCmd.AddCommand(newCmd)
newCmd.Flags().IntP("height", "H", 20, "Height of the selection prompt")
} }
// 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, err := cmd.Flags().GetInt("height") height := viper.GetInt("height")
if err != nil { if height <= 0 {
return fmt.Errorf("error getting height flag: %w", err) return errors.New("height must be a positive integer")
} }
client, ok := clientFromContext(cmd.Context()) client, ok := clientFromContext(cmd.Context())