mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 17:24:49 +00:00
Simplify linters config, fix cyclop issues in main.go
This commit is contained in:
121
.golangci.yml
121
.golangci.yml
@@ -1,115 +1,20 @@
|
|||||||
version: 2
|
version: "2"
|
||||||
|
|
||||||
run:
|
run:
|
||||||
timeout: 5m
|
timeout: 1m
|
||||||
go: '1.24'
|
|
||||||
|
|
||||||
linters-settings:
|
formatters:
|
||||||
errcheck:
|
enable:
|
||||||
check-type-assertions: true
|
- gci
|
||||||
check-blank: true
|
- gofmt
|
||||||
|
- goimports
|
||||||
govet:
|
|
||||||
enable-all: true
|
|
||||||
disable:
|
|
||||||
- shadow
|
|
||||||
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 15
|
|
||||||
|
|
||||||
dupl:
|
|
||||||
threshold: 100
|
|
||||||
|
|
||||||
goconst:
|
|
||||||
min-len: 3
|
|
||||||
min-occurrences: 3
|
|
||||||
|
|
||||||
lll:
|
|
||||||
line-length: 120
|
|
||||||
|
|
||||||
unparam:
|
|
||||||
check-exported: false
|
|
||||||
|
|
||||||
nakedret:
|
|
||||||
max-func-lines: 30
|
|
||||||
|
|
||||||
prealloc:
|
|
||||||
simple: true
|
|
||||||
range-loops: true
|
|
||||||
for-loops: false
|
|
||||||
|
|
||||||
gocritic:
|
|
||||||
enabled-tags:
|
|
||||||
- diagnostic
|
|
||||||
- experimental
|
|
||||||
- opinionated
|
|
||||||
- performance
|
|
||||||
- style
|
|
||||||
|
|
||||||
funlen:
|
|
||||||
lines: 100
|
|
||||||
statements: 50
|
|
||||||
|
|
||||||
godox:
|
|
||||||
keywords:
|
|
||||||
- NOTE
|
|
||||||
- OPTIMIZE
|
|
||||||
- HACK
|
|
||||||
|
|
||||||
dogsled:
|
|
||||||
max-blank-identifiers: 2
|
|
||||||
|
|
||||||
whitespace:
|
|
||||||
multi-if: false
|
|
||||||
multi-func: false
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
default: all
|
||||||
enable:
|
|
||||||
- bodyclose
|
|
||||||
- dogsled
|
|
||||||
- dupl
|
|
||||||
- errcheck
|
|
||||||
- funlen
|
|
||||||
- gochecknoinits
|
|
||||||
- goconst
|
|
||||||
- gocritic
|
|
||||||
- gocyclo
|
|
||||||
- godox
|
|
||||||
- goprintffuncname
|
|
||||||
- gosec
|
|
||||||
- govet
|
|
||||||
- ineffassign
|
|
||||||
- lll
|
|
||||||
- misspell
|
|
||||||
- nakedret
|
|
||||||
- noctx
|
|
||||||
- nolintlint
|
|
||||||
- prealloc
|
|
||||||
- revive
|
|
||||||
- staticcheck
|
|
||||||
- unconvert
|
|
||||||
- unparam
|
|
||||||
- unused
|
|
||||||
- whitespace
|
|
||||||
|
|
||||||
issues:
|
exclusions:
|
||||||
exclude-rules:
|
rules:
|
||||||
- path: _test\.go
|
- path: _test.go
|
||||||
linters:
|
linters:
|
||||||
- funlen
|
- dupl # We don't mind duplicated code in tests. It helps with clarity
|
||||||
- goconst
|
|
||||||
- lll
|
|
||||||
|
|
||||||
- path: pkg/git/test/
|
|
||||||
linters:
|
|
||||||
- goconst
|
|
||||||
|
|
||||||
exclude-use-default: false
|
|
||||||
max-issues-per-linter: 0
|
|
||||||
max-same-issues: 0
|
|
||||||
|
|
||||||
output:
|
|
||||||
format: colored-line-number
|
|
||||||
print-issued-lines: true
|
|
||||||
print-linter-name: true
|
|
||||||
78
README.md
78
README.md
@@ -296,40 +296,6 @@ git list --fetch
|
|||||||
git list --out dump > backup-$(date +%Y%m%d).txt
|
git list --out dump > backup-$(date +%Y%m%d).txt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
Run the test suite:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Run all tests
|
|
||||||
go test ./...
|
|
||||||
|
|
||||||
# Run tests with coverage
|
|
||||||
go test -race -coverprofile=coverage.out ./...
|
|
||||||
go tool cover -html=coverage.out
|
|
||||||
|
|
||||||
# Run specific package tests
|
|
||||||
go test -v ./pkg/git
|
|
||||||
```
|
|
||||||
|
|
||||||
### Linting
|
|
||||||
|
|
||||||
This project uses comprehensive linting with golangci-lint. The linting configuration includes 25+ linters for code quality, security, and style checking.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Install golangci-lint (if not already installed)
|
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
|
||||||
|
|
||||||
# Run linting with the project's configuration
|
|
||||||
golangci-lint run
|
|
||||||
|
|
||||||
# Run with verbose output
|
|
||||||
golangci-lint run -v
|
|
||||||
|
|
||||||
# Fix auto-fixable issues
|
|
||||||
golangci-lint run --fix
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Common Issues
|
### Common Issues
|
||||||
@@ -373,19 +339,51 @@ git get user/repo
|
|||||||
|
|
||||||
We welcome contributions!
|
We welcome contributions!
|
||||||
|
|
||||||
### Quick Start for Contributors
|
### Quick Start
|
||||||
|
|
||||||
1. **Fork the repository**
|
1. **Fork the repository**
|
||||||
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
|
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
|
||||||
3. **Install dependencies**: `go mod download`
|
3. **Install dependencies**: `go mod download`
|
||||||
4. **Make changes and add tests**
|
4. **Make changes and add tests**
|
||||||
5. **Format**: `go fmt ./...`
|
5. **Format**: `go fmt ./...`
|
||||||
6. **Run tests**: `go test ./...`
|
6. **Build**: `go build -o git-get ./cmd/`
|
||||||
7. **Run linter**: `golangci-lint run`
|
7. **Run tests**: `go test ./...`
|
||||||
8. **Commit changes**: `git commit -m 'Add amazing feature'`
|
8. **Run linter**: `golangci-lint run`
|
||||||
9. **Push to branch**: `git push origin feature/amazing-feature`
|
9. **Commit changes**: `git commit -m 'Add amazing feature'`
|
||||||
10. **Open a Pull Request**
|
10. **Push to branch**: `git push origin feature/amazing-feature`
|
||||||
|
11. **Open a Pull Request**
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
Run the test suite:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests
|
||||||
|
go test ./...
|
||||||
|
|
||||||
|
# Run tests with coverage
|
||||||
|
go test -race -coverprofile=coverage.out ./...
|
||||||
|
go tool cover -html=coverage.out
|
||||||
|
|
||||||
|
# Run specific package tests
|
||||||
|
go test -v ./pkg/git
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install golangci-lint (if not already installed)
|
||||||
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
|
|
||||||
|
# Run linting with the project's configuration
|
||||||
|
golangci-lint run
|
||||||
|
|
||||||
|
# Run with verbose output
|
||||||
|
golangci-lint run -v
|
||||||
|
|
||||||
|
# Fix auto-fixable issues
|
||||||
|
golangci-lint run --fix
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
68
cmd/main.go
68
cmd/main.go
@@ -6,56 +6,54 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// This program behaves as a git subcommand (see https://git.github.io/htmldocs/howto/new-command.html)
|
||||||
|
// When added to PATH, git recognizes it as its subcommand and it can be invoked as "git get..." or "git list..."
|
||||||
|
// It can also be invoked as a regular binary with subcommands: "git-get get..." or "git-get list"
|
||||||
|
// The following flow detects the invokation method and runs the appropriate command.
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// This program behaves as a git subcommand (see https://git.github.io/htmldocs/howto/new-command.html)
|
command, args := determineCommand()
|
||||||
// When added to PATH, git recognizes it as its subcommand and it can be invoked as "git get..." or "git list..."
|
executeCommand(command, args)
|
||||||
// It can also be invoked as a regular binary with subcommands: "git-get get..." or "git-get list"
|
}
|
||||||
// The following flow detects the invokation method and runs the appropriate command.
|
|
||||||
|
|
||||||
programName := filepath.Base(os.Args[0])
|
func determineCommand() (string, []string) {
|
||||||
|
programName := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
||||||
// Remove common executable extensions
|
|
||||||
programName = strings.TrimSuffix(programName, ".exe")
|
|
||||||
|
|
||||||
// Determine which command to run based on program name or first argument
|
|
||||||
var command string
|
|
||||||
var args []string
|
|
||||||
|
|
||||||
switch programName {
|
switch programName {
|
||||||
case "git-get":
|
case "git-get":
|
||||||
// Check if first argument is a subcommand
|
return handleGitGetInvocation()
|
||||||
if len(os.Args) > 1 && (os.Args[1] == "get" || os.Args[1] == "list") {
|
|
||||||
// Called as: git-get get <repo> or git-get list
|
|
||||||
command = os.Args[1]
|
|
||||||
args = os.Args[2:]
|
|
||||||
} else {
|
|
||||||
// Called as: git-get <repo> (default to get command)
|
|
||||||
command = "get"
|
|
||||||
args = os.Args[1:]
|
|
||||||
}
|
|
||||||
case "git-list":
|
case "git-list":
|
||||||
// Called as: git-list (symlinked binary)
|
return handleGitListInvocation()
|
||||||
command = "list"
|
|
||||||
args = os.Args[1:]
|
|
||||||
default:
|
default:
|
||||||
// Fallback: use first argument as command
|
return handleDefaultInvocation()
|
||||||
if len(os.Args) > 1 {
|
|
||||||
command = os.Args[1]
|
|
||||||
args = os.Args[2:]
|
|
||||||
} else {
|
|
||||||
command = "get"
|
|
||||||
args = []string{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute the appropriate command
|
func handleGitGetInvocation() (string, []string) {
|
||||||
|
if len(os.Args) > 1 && (os.Args[1] == "get" || os.Args[1] == "list") {
|
||||||
|
return os.Args[1], os.Args[2:]
|
||||||
|
}
|
||||||
|
return "get", os.Args[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleGitListInvocation() (string, []string) {
|
||||||
|
return "list", os.Args[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleDefaultInvocation() (string, []string) {
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
return os.Args[1], os.Args[2:]
|
||||||
|
}
|
||||||
|
return "get", []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeCommand(command string, args []string) {
|
||||||
switch command {
|
switch command {
|
||||||
case "get":
|
case "get":
|
||||||
runGet(args)
|
runGet(args)
|
||||||
case "list":
|
case "list":
|
||||||
runList(args)
|
runList(args)
|
||||||
default:
|
default:
|
||||||
// Default to get command for unknown commands
|
|
||||||
runGet(os.Args[1:])
|
runGet(os.Args[1:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user