Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ linters:
- revive
- noinlineerr
- wsl
- gomodguard
43 changes: 25 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
module github.com/corani/adr

go 1.25.0
go 1.25.8

require (
github.com/MichaelMure/go-term-markdown v0.1.4
charm.land/glamour/v2 v2.0.1
charm.land/lipgloss/v2 v2.0.4
github.com/adrg/frontmatter v0.2.0
github.com/goccy/go-yaml v1.19.2
github.com/gosimple/slug v1.15.0
github.com/jedib0t/go-pretty/v6 v6.8.3
github.com/spf13/cobra v1.10.2
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/MichaelMure/go-term-text v0.3.1 // indirect
github.com/alecthomas/chroma v0.7.1 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.1.6 // indirect
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20251205161215-1948445e3318 // indirect
github.com/charmbracelet/x/ansi v0.11.7 // indirect
github.com/charmbracelet/x/exp/slice v0.0.0-20250327172914-2fdc97757edf // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gomarkdown/markdown v0.0.0-20260411013819-759bbc3e3207 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kyokomi/emoji/v2 v2.2.8 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/lucasb-eyer/go-colorful v1.4.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.23 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand All @@ -43,8 +47,11 @@ require (
github.com/spf13/pflag v1.0.9 // indirect
github.com/spf13/viper v1.10.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/image v0.41.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.7.8 // indirect
github.com/yuin/goldmark-emoji v1.0.5 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
Expand Down
115 changes: 63 additions & 52 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/adr/adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/adrg/frontmatter"
"github.com/corani/adr/config"
"github.com/gosimple/slug"
"gopkg.in/yaml.v3"
"github.com/goccy/go-yaml"
)

type Status string
Expand Down
42 changes: 26 additions & 16 deletions internal/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,47 @@ package app

import (
"fmt"
"os"
"slices"
"strings"

"charm.land/glamour/v2"
"charm.land/lipgloss/v2"
"github.com/corani/adr/config"
"github.com/corani/adr/internal/adr"
"github.com/jedib0t/go-pretty/v6/table"
)

func List(conf *config.Config) error {
tbl := table.NewWriter()

tbl.SetOutputMirror(os.Stdout)
tbl.SetStyle(table.StyleRounded)
tbl.SortBy([]table.SortBy{{
Name: "#",
Mode: table.AscNumeric,
Number: 0,
IgnoreCase: false,
CustomLess: nil,
}})
tbl.AppendHeader(table.Row{"#", "date", "status", "title"})
var rows []string

err := adr.ForEach(conf, func(v *adr.Adr) error {
tbl.AppendRow(table.Row{fmt.Sprintf("%04d", v.Number), v.Date, v.Status, v.Title})
rows = append(rows, fmt.Sprintf("| %04d | %s | %s | %s |", v.Number, v.Date, v.Status, v.Title))

return nil
})
if err != nil {
return fmt.Errorf("%w: list: %w", ErrInternal, err)
}

tbl.Render()
slices.Sort(rows)

table := "| # | date | status | title |\n|---|------|--------|-------|\n" + strings.Join(rows, "\n") + "\n"

renderer, err := glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamour.WithWordWrap(0),
)
if err != nil {
return fmt.Errorf("%w: list: %w", ErrInternal, err)
}

out, err := renderer.Render(table)
if err != nil {
return fmt.Errorf("%w: list: %w", ErrInternal, err)
}

if _, err = lipgloss.Print(out); err != nil {
return fmt.Errorf("%w: list: %w", ErrInternal, err)
}

return nil
}
47 changes: 25 additions & 22 deletions internal/app/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package app

import (
"fmt"
"os"
"strings"

markdown "github.com/MichaelMure/go-term-markdown"
"charm.land/glamour/v2"
"charm.land/lipgloss/v2"
"github.com/corani/adr/config"
"github.com/corani/adr/internal/adr"
"github.com/jedib0t/go-pretty/v6/table"
)

func Show(conf *config.Config, number int) error {
Expand All @@ -16,28 +16,31 @@ func Show(conf *config.Config, number int) error {
return fmt.Errorf("%w: show: %w", ErrInternal, err)
}

tbl := table.NewWriter()

tbl.SetOutputMirror(os.Stdout)
tbl.SetStyle(table.StyleRounded)
tbl.AppendRows([]table.Row{
{"Filename", found.Filename},
{"Number", fmt.Sprintf("%04d", found.Number)},
{"Date", found.Date},
{"Status", found.Status},
})

tbl.Render()

const (
width = 80
indent = 1
meta := strings.Join([]string{
"| field | value |",
"|-------|-------|",
fmt.Sprintf("| Filename | %s |", found.Filename),
fmt.Sprintf("| Number | %04d |", found.Number),
fmt.Sprintf("| Date | %s |", found.Date),
fmt.Sprintf("| Status | %s |", found.Status),
}, "\n") + "\n\n" + string(found.Body)

renderer, err := glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamour.WithWordWrap(0),
)
if err != nil {
return fmt.Errorf("%w: show: %w", ErrInternal, err)
}

out := markdown.Render(string(found.Body), width, indent)
out, err := renderer.Render(meta)
if err != nil {
return fmt.Errorf("%w: show: %w", ErrInternal, err)
}

fmt.Println()
fmt.Println(string(out))
if _, err = lipgloss.Print(out); err != nil {
return fmt.Errorf("%w: show: %w", ErrInternal, err)
}

return nil
}
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"

"github.com/corani/adr/config"
"gopkg.in/yaml.v3"
"github.com/goccy/go-yaml"
)

type Config = config.Config
Expand Down
Loading