Skip to content

Commit 84efbd3

Browse files
authored
feat: add template subcommand (#7)
* chore: improve install script - improved script to either install or update when version is lower than release version. * chore: update release-please github action - deleted the scripts/build script - moved the logic from the scripts/build script to the release-please action * chore: use defaults for go dependency checking - removed settings for day, time, and timezone from dependency checking for go mod The dependabot now uses the default weekly time settings. * chore: fix pre-commit git hook - removed adding all files after running go formatter This fixes issue of unwanted files/directories added to the commit. * feat: add template subcommand - created template subcommand for use with git hook templates (reusable git hooks) - created subcommands for template to create, copy, edit, and remove templates. * feat: add config subcommand - created HkUp configuration settings - created subcommands for config to get and set configuration settings NOTE: this feature is hidden and will be available when configuration settings are finalized. * refactor(cmd): simplify flag handling & init logic - Rename flags for consistency: `Lang` to `LangFlg`, `GitDir` to `GitDirFlg`, and `WorkTree` to `WorkTreeFlg`. - Consolidate command registration in `root.go` by removing redundant `rootCmd.AddCommand` calls from individual command files (add.go, remove.go, list.go, doc.go). - Simplify `init()` functions in command files to centralize logic. - Update root command version handling to dynamically use `version` variable. - Clarify documentation comment in `main.go`. * refactor(logic): update flags and simplify hook commands - Rename flags: `Lang` to `LangFlg`, `GitDir` to `GitDirFlg`, `WorkTree` to `WorkTreeFlg` for consistency. - Simplify the Add, Remove, and Init logic by centralizing directory checks and reducing redundant code. - Update file handling to improve readability and error handling. - Adjust comments for better clarity and consistency across functions. * refactor(git): improve comments and simplify hook logic - Updated comments for clarity and consistency in the Git package. - Removed unnecessary constant `HookDocSite`, and clarified hook documentation URL logic. - Simplified the `GetHook` and `GetLang` functions to improve readability and error handling. - Updated the `supportedLangs` map to explicitly include `sh` and `bash`, ensuring clearer intent. * feat(util): add file ops, prompts, and config functions - Added utility functions for terminal prompts, including YesNoPrompt and UserInputPrompt, to improve user interaction. - Expanded file handling functions, including CreateDirectory and CopyFile, to support additional use cases. - Introduced functions to handle HkUp configuration paths: - GetConfigDirPath - GetConfigFilePath - GetTemplateDirPath - Added functions for TOML file manipulation: - GetTOMLValue (retrieve a value from a TOML file) - SetTOMLValue (set a value in a TOML file) - Implemented GetEditor function to determine the default editor for HkUp from configuration, git, or environment variables. - Refactored existing functions for clarity and consistency (e.g., CreateFile, DoesDirectoryExist).
1 parent 1c7753d commit 84efbd3

39 files changed

+1319
-237
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "weekly"
7-
day: "friday"
8-
time: "12:00"
9-
timezone: "America/New_York"
107
- package-ecosystem: "github-actions"
118
directory: "/"
129
schedule:

.github/workflows/release-please.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@v4
1919

20-
# Step 2: Run your build script
21-
- name: Run build script
22-
run: |
23-
rm -rf ./bin
24-
chmod +x ./scripts/build
25-
./scripts/build
20+
# Step 2: Set up Go environment
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version-file: 'go.mod'
2625

2726
# Step 3: Use release-please to create a release
2827
- name: Create release
@@ -31,12 +30,29 @@ jobs:
3130
with:
3231
release-type: go
3332

34-
# Step 4: Upload Release Artifacts if a release was created
33+
# Step 4: Update the version in the build and perform multi-platform builds
34+
- name: Build for multiple platforms
35+
if: ${{ steps.release.outputs.release_created }}
36+
run: |
37+
VERSION="${{ steps.release.outputs.version }}"
38+
echo "Updating version to ${VERSION}"
39+
40+
mkdir -p bin
41+
42+
# Build for Linux
43+
GOOS=linux GOARCH=amd64 go build -o bin/hkup-linux -ldflags="-s -w -X cmd.version=${VERSION}" .
44+
45+
# Build for Darwin/macOS
46+
GOOS=darwin GOARCH=amd64 go build -o bin/hkup-darwin -ldflags="-s -w -X cmd.version=${VERSION}" .
47+
48+
# Build for Windows (optional, uncomment if needed)
49+
# GOOS=windows GOARCH=amd64 go build -o bin/hkup.exe -ldflags="-s -w -X cmd.version=${VERSION}" .
50+
51+
# Step 5: Upload Release Artifacts if a release was created
3552
- name: Upload Release Artifacts
3653
if: ${{ steps.release.outputs.release_created }}
3754
env:
3855
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3956
run: |
4057
gh release upload ${{ steps.release.outputs.tag_name }} \
41-
./bin/*
42-
58+
bin/*

.hkup/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
if git diff --cached --name-only | grep -q '\.go$'; then
55
echo "Formatting Go files..."
66
gofmt -w .
7-
echo ""
87

9-
# Add formatted files to the staging area
10-
git add .
118
else
129
echo "No Go files changed. Skipping formatting."
1310
echo ""

README.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# HkUp
2-
Your CLI tool with benefits built by [iton0](https://github.com/iton0) in [Go](https://go.dev/)!
2+
> Your CLI tool with benefits built by [iton0](https://github.com/iton0) in [Go](https://go.dev/)!
33
44
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/iton0/hkup-cli)](https://github.com/iton0/hkup-cli/releases/latest)
55
[![godoc](https://godoc.org/github.com/iton0/hkup-cli?status.svg)](http://godoc.org/github.com/iton0/hkup-cli)
@@ -11,9 +11,16 @@ Your CLI tool with benefits built by [iton0](https://github.com/iton0) in [Go](h
1111
## Introduction
1212
Git hooks automate and implement processes in your workflow, increasing code quality and consistency.
1313

14-
However, many developers avoid git hooks due to a lack of awareness and the perceived complexity of setup, discouraging them from using this feature.
14+
Common use cases include:
15+
- Commit Message Validation
16+
- Environment Configuration
17+
- Formatting
18+
- Linting
19+
- Testing
1520

16-
**HkUp** simplifies the management of git hooks, allowing you to focus on the logic and usage of your hooks instead.
21+
However, many developers avoid Git hooks due to a lack of awareness and the perceived complexity of setup, discouraging them from using this feature.
22+
23+
**HkUp** simplifies the management of Git hooks, allowing you to focus on the logic and usage of your hooks instead.
1724

1825
## Installation
1926
External Dependencies:
@@ -27,10 +34,9 @@ Run the script below (supports Linux and macOS):
2734
curl -sSL https://raw.githubusercontent.com/iton0/hkup-cli/main/scripts/install | sh
2835
```
2936
> [!Tip]
30-
> To update HkUp, rerun the above script.
31-
> It will replace the current version.
37+
> To update HkUp, simply rerun the script above. It will automatically replace your current version with the latest release.
3238
33-
#### Uninstalling hkup
39+
### Uninstalling HkUp
3440

3541
```sh
3642
# Locates and deletes the HkUp binary
@@ -40,49 +46,63 @@ sh -c 'rm "$(command -v 'hkup')"'
4046
</details>
4147

4248
## Usage Quickstart
43-
This section provides basic information about core usage. For detailed options run `hkup --help`.
49+
This section provides basic information about core usage. For detailed usage information run `hkup --help`.
4450

45-
#### Initializing hkup
51+
### Initializing hkup
4652
Run the following command in your git repository to initialize HkUp:
4753
```sh
4854
hkup init
4955
```
5056

51-
This command creates a **.hkup** folder and sets the local **core.hooksPath** variable. If the folder already exists, it will simply update the path variable. The path is relative, ensuring that moving your repository won’t affect hook sourcing.
57+
This creates a **.hkup** directory and sets the local **core.hooksPath** variable. If the directory already exists, it will simply update the path variable. The path is relative, ensuring that moving your repository won’t affect hook sourcing.
5258

53-
#### Adding & Removing hooks
59+
### Adding & Removing hooks
5460
Add or remove hooks easily with:
5561
```sh
5662
hkup add <hook-name>
63+
5764
hkup remove <hook-name>
5865
```
5966

60-
#### Info & Docs
61-
There are two commands that will help you with both HkUp and git hooks:
62-
63-
**`hkup list {hook|lang}`**
64-
Outputs list of either available hooks or supported languages.
67+
### Templates
68+
A **template** is a pre-configured, reusable Git hook that simplifies and automates the process of setting up hooks in a Git repository. With **HkUp**, you can create, copy, edit, or remove templates, allowing for consistent and easy application of hooks without needing to rewrite scripts each time.
6569

66-
**`hkup doc <hook-name>`**
67-
Opens your browser with Git documentation for the specified git hook, helping you understand its usage.
70+
The templates are stored in the HkUp config templates directory that can either be found at **$XDG_CONFIG_HOME/hkup/templates** or **$HOME/.config/hkup/templates** depending on your system.
6871

69-
## Future TODOs
70-
- [ ] make an update subcommand
71-
- [ ] store custom git hooks as templates for future use (via add template subcmd)
72-
- Allow users to create, store, and share templates for common hooks. Users can fetch these templates over the network.
73-
- [ ] branch-specific hooks
74-
- [ ] logo maybe?
72+
#### Naming Convention
73+
Template files follow the naming convention:
74+
`<template-name>#<hook-name>`
75+
Where:
76+
- `<template-name>` is the name of the template.
77+
- `<hook-name>` is the specific Git hook (e.g., pre-commit, post-merge).
7578

76-
## Contributing
77-
HkUp welcomes contributions to enhance this CLI application! Before submitting a pull request (PR) for a new feature, please follow these steps:
79+
**Create a template**:
80+
```sh
81+
hkup template create
82+
# OR
83+
hkup template create <hook-name>
84+
```
7885

79-
1. **Create an Issue**:
80-
If you have an idea for a new feature, please create a new issue in the repository using the **feature_request** template. Provide a clear description of the feature and its potential benefits. Please note that issues submitted without using the template may be closed without warning.
86+
**Copy a template** into current working directory:
87+
```sh
88+
hkup template copy <template-name>
89+
```
8190

82-
2. **Wait for Approval**:
83-
Once you submit your issue, I’ll review it and provide feedback. If I approve the feature request, I will let you know that you're free to proceed with your PR.
91+
**Edit a template**:
92+
```sh
93+
hkup template edit <template-name>
94+
```
95+
>[!CAUTION]
96+
> Editing a template will not update its copies.
8497
85-
3. **Submit Your PR**:
86-
After receiving approval, you can create your PR. Be sure to reference the issue in your PR description.
98+
**Remove a template**:
99+
```sh
100+
hkup template remove <template-name>
101+
```
87102

88-
Please note that PRs submitted without prior approval through an issue may be closed without merging. This process helps us manage feature requests effectively and ensures that contributions align with the project’s goals.
103+
## Roadmap to v1.0.0
104+
1. windows support
105+
2. wrapper for git init & clone and gh repo create & clone
106+
3. HkUp logo (may or may not keep this one)
107+
4. better test coverage
108+
5. Allow users to create, store, and share templates. Users can fetch these templates over internet (may need to make another repo for this).

cmd/add.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ var (
1818
)
1919

2020
func init() {
21-
addCmd.Flags().StringVar(&logic.Lang, "lang", "", "supported languages for git hooks")
22-
rootCmd.AddCommand(addCmd)
21+
addCmd.Flags().StringVar(&logic.LangFlg, "lang", "", "supported languages for git hooks")
2322
}

cmd/config/get.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package config
2+
3+
import (
4+
"github.com/iton0/hkup-cli/internal/logic/config"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var (
9+
getCmd = &cobra.Command{
10+
Use: "get <config-setting>",
11+
Short: "Get a HkUp config setting",
12+
Args: cobra.ExactArgs(1),
13+
RunE: config.Get,
14+
}
15+
)
16+
17+
func init() {}

cmd/config/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
Package template initializes the config subcommand and its subcommands.
3+
4+
This package is utilized in the root command of [github.com/iton0/hkup-cli/cmd]
5+
package.
6+
*/
7+
package config
8+
9+
// NOTE: This file is for documentation purposes and should be kept empty.

cmd/config/root.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package config
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var (
8+
// RootCmd is the config command that will be added to the root HkUp command.
9+
RootCmd = &cobra.Command{
10+
Use: "config",
11+
Short: "HkUp configuration settings",
12+
Hidden: true, // TODO: remove after finalizing configuration settings
13+
}
14+
)
15+
16+
func init() {
17+
RootCmd.AddCommand(getCmd)
18+
RootCmd.AddCommand(setCmd)
19+
}

cmd/config/set.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package config
2+
3+
import (
4+
"github.com/iton0/hkup-cli/internal/logic/config"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var (
9+
setCmd = &cobra.Command{
10+
Use: "set <config-setting> <value>",
11+
Short: "Set a HkUp config setting",
12+
Args: cobra.ExactArgs(2),
13+
RunE: config.Set,
14+
}
15+
)
16+
17+
func init() {}

cmd/doc.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ var (
1818
}
1919
)
2020

21-
func init() {
22-
rootCmd.AddCommand(docCmd)
23-
}
21+
func init() {}

0 commit comments

Comments
 (0)