Skip to content

Commit 8cb0482

Browse files
Add headerLevel option (#53)
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
1 parent 82a1498 commit 8cb0482

File tree

9 files changed

+51
-24
lines changed

9 files changed

+51
-24
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ jobs:
9494
- checkout
9595
- restore_cache:
9696
keys:
97-
- v1-golangci-lint-{{ checksum "go.sum" }}
97+
- v2-golangci-lint-{{ checksum "go.sum" }}
9898
- run:
9999
name: lint
100100
command: make lint
101101
- save_cache:
102-
key: v1-golangci-lint-{{ checksum "go.sum" }}
102+
key: v2-golangci-lint-{{ checksum "go.sum" }}
103103
paths:
104104
- *gocache
105-
- build/golangci-lint
106105

107106
test:
108107
executor: container

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ run:
55
linters:
66
disable-all: true
77
enable:
8+
- asciicheck
89
- bodyclose
910
- deadcode
1011
- depguard
@@ -21,6 +22,7 @@ linters:
2122
- gofmt
2223
- goimports
2324
- golint
25+
- gomodguard
2426
- goprintffuncname
2527
- gosec
2628
- gosimple
@@ -31,20 +33,25 @@ linters:
3133
- maligned
3234
- misspell
3335
- nakedret
36+
- nolintlint
3437
- prealloc
3538
- rowserrcheck
3639
- scopelint
3740
- staticcheck
3841
- structcheck
3942
- stylecheck
43+
- testpackage
4044
- typecheck
4145
- unconvert
4246
- unparam
4347
- unused
4448
- varcheck
4549
- whitespace
4650
# - funlen
51+
# - godot
52+
# - goerr113
4753
# - gomnd
54+
# - nestif
4855
# - wsl
4956
linters-settings:
5057
errcheck:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $(GO_MODIFF_STATIC):
4949

5050
$(GOLANGCI_LINT):
5151
export \
52-
VERSION=v1.24.0 \
52+
VERSION=v1.27.0 \
5353
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
5454
BINDIR=$(BUILD_PATH) && \
5555
curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION

cmd/go-modiff/main.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ import (
1212
)
1313

1414
const (
15-
repositoryArg = "repository"
16-
fromArg = "from"
17-
toArg = "to"
18-
linkArg = "link"
15+
repositoryArg = "repository"
16+
fromArg = "from"
17+
toArg = "to"
18+
linkArg = "link"
19+
headerLevelArg = "header-level"
1920
)
2021

2122
func main() {
2223
const debugFlag = "debug"
2324

2425
app := ccli.NewApp()
2526
app.Name = "go-modiff"
26-
app.Version = "1.0.3"
27+
app.Version = "1.1.0"
2728
app.Authors = []*cli.Author{
2829
{Name: "Sascha Grunert", Email: "mail@saschagrunert.de"},
2930
}
@@ -57,6 +58,12 @@ func main() {
5758
Aliases: []string{"l"},
5859
Usage: "add diff links to the markdown output",
5960
},
61+
&cli.UintFlag{
62+
Name: headerLevelArg,
63+
Aliases: []string{"i"},
64+
Value: 1,
65+
Usage: "add a higher markdown header level depth",
66+
},
6067
&cli.BoolFlag{
6168
Name: debugFlag,
6269
Aliases: []string{"d"},
@@ -101,6 +108,7 @@ func main() {
101108
c.String(fromArg),
102109
c.String(toArg),
103110
c.Bool(linkArg),
111+
c.Uint(headerLevelArg),
104112
)
105113
res, err := modiff.Run(config)
106114
if err != nil {

completions/go-modiff.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l repository -s r
1313
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l from -s f -r -d 'the start of the comparison, any valid git rev'
1414
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l to -s t -r -d 'the end of the comparison, any valid git rev'
1515
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l link -s l -d 'add diff links to the markdown output'
16+
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l header-level -s i -r -d 'add a higher markdown header level depth'
1617
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l debug -s d -d 'enable debug output'
1718
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l help -s h -d 'show help'
1819
complete -c go-modiff -n '__fish_go-modiff_no_subcommand' -f -l version -s v -d 'print the version'

docs/go-modiff.8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go\-modiff
1616
.nf
1717
[\-\-debug|\-d]
1818
[\-\-from|\-f]=[value]
19+
[\-\-header\-level|\-i]=[value]
1920
[\-\-help|\-h]
2021
[\-\-link|\-l]
2122
[\-\-repository|\-r]=[value]
@@ -50,6 +51,9 @@ go\-modiff [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
5051
.PP
5152
\fB\-\-from, \-f\fP="": the start of the comparison, any valid git rev (default: master)
5253

54+
.PP
55+
\fB\-\-header\-level, \-i\fP="": add a higher markdown header level depth (default: 1)
56+
5357
.PP
5458
\fB\-\-help, \-h\fP: show help
5559

docs/go-modiff.8.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go-modiff
1111
```
1212
[--debug|-d]
1313
[--from|-f]=[value]
14+
[--header-level|-i]=[value]
1415
[--help|-h]
1516
[--link|-l]
1617
[--repository|-r]=[value]
@@ -34,6 +35,8 @@ go-modiff [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
3435

3536
**--from, -f**="": the start of the comparison, any valid git rev (default: master)
3637

38+
**--header-level, -i**="": add a higher markdown header level depth (default: 1)
39+
3740
**--help, -h**: show help
3841

3942
**--link, -l**: add diff links to the markdown output

pkg/modiff/modiff.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ type modules = map[string]versions
2121

2222
// Config is the structure passed to `Run`
2323
type Config struct {
24-
repository string
25-
from string
26-
to string
27-
link bool
24+
repository string
25+
from string
26+
to string
27+
link bool
28+
headerLevel uint
2829
}
2930

3031
// NewConfig creates a new configuration
31-
func NewConfig(repository, from, to string, link bool) *Config {
32-
return &Config{repository, from, to, link}
32+
func NewConfig(repository, from, to string, link bool, headerLevel uint) *Config {
33+
return &Config{repository, from, to, link, headerLevel}
3334
}
3435

3536
// Run starts go modiff and returns the markdown string
@@ -74,7 +75,7 @@ func Run(config *Config) (string, error) {
7475
if err != nil {
7576
return "", err
7677
}
77-
return diffModules(mods, config.link), nil
78+
return diffModules(mods, config.link, config.headerLevel), nil
7879
}
7980

8081
func toURL(name string) string {
@@ -95,7 +96,7 @@ func logErr(msg interface{}) (string, error) {
9596
return "", err
9697
}
9798

98-
func diffModules(mods modules, addLinks bool) string {
99+
func diffModules(mods modules, addLinks bool, headerLevel uint) string {
99100
var added, removed, changed []string
100101
for name, mod := range mods {
101102
txt := fmt.Sprintf("- %s: ", name)
@@ -135,9 +136,13 @@ func diffModules(mods modules, addLinks bool) string {
135136

136137
// Pretty print
137138
builder := &strings.Builder{}
138-
builder.WriteString("# Dependencies\n")
139+
builder.WriteString(fmt.Sprintf(
140+
"%s Dependencies\n", strings.Repeat("#", int(headerLevel)),
141+
))
139142
forEach := func(section string, input []string) {
140-
builder.WriteString(fmt.Sprintf("\n## %s\n", section))
143+
builder.WriteString(fmt.Sprintf("\n%s %s\n",
144+
strings.Repeat("#", int(headerLevel)+1), section,
145+
))
141146
if len(input) > 0 {
142147
for _, mod := range input {
143148
builder.WriteString(fmt.Sprintf("%s\n", mod))

pkg/modiff/modiff_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _Nothing has changed._
5252

5353
It("should succeed", func() {
5454
// Given
55-
config := modiff.NewConfig(repo, from, to, false)
55+
config := modiff.NewConfig(repo, from, to, false, 1)
5656

5757
// When
5858
res, err := modiff.Run(config)
@@ -64,7 +64,7 @@ _Nothing has changed._
6464

6565
It("should succeed with links", func() {
6666
// Given
67-
config := modiff.NewConfig(repo, from, to, true)
67+
config := modiff.NewConfig(repo, from, to, true, 1)
6868

6969
// When
7070
res, err := modiff.Run(config)
@@ -86,7 +86,7 @@ _Nothing has changed._
8686

8787
It("should fail if 'repository' not given", func() {
8888
// Given
89-
config := modiff.NewConfig("", from, to, true)
89+
config := modiff.NewConfig("", from, to, true, 1)
9090

9191
// When
9292
res, err := modiff.Run(config)
@@ -98,7 +98,7 @@ _Nothing has changed._
9898

9999
It("should fail if 'from' equals 'to'", func() {
100100
// Given
101-
config := modiff.NewConfig(repo, "", "", true)
101+
config := modiff.NewConfig(repo, "", "", true, 1)
102102

103103
// When
104104
res, err := modiff.Run(config)
@@ -110,7 +110,7 @@ _Nothing has changed._
110110

111111
It("should fail if repository is not clone-able", func() {
112112
// Given
113-
config := modiff.NewConfig("invalid", from, "", true)
113+
config := modiff.NewConfig("invalid", from, "", true, 1)
114114

115115
// When
116116
res, err := modiff.Run(config)

0 commit comments

Comments
 (0)