Skip to content

Commit

Permalink
refactor: consolidate the two public packages (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHope committed May 30, 2024
1 parent a20ff45 commit baa6bd0
Show file tree
Hide file tree
Showing 62 changed files with 835 additions and 769 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ tasks:
test-internal:
dir: internal
cmds:
- go test ./...
- go test -count=1 ./...
test-cmd:
dir: cmd
cmds:
- go test --tags "fts5" ./...
- go test -count=1 --tags "fts5" ./...
test:
cmds:
- task: test-internal
Expand Down
73 changes: 36 additions & 37 deletions cmd/cli/internal/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"time"

"github.com/jonathanhope/armaria/cmd/cli/tui"
"github.com/jonathanhope/armaria/pkg/api"
"github.com/jonathanhope/armaria/pkg/model"
"github.com/jonathanhope/armaria/pkg"
)

// RootCmd is the top level CLI command for Armaria.
Expand Down Expand Up @@ -107,7 +106,7 @@ type AddBookCmd struct {
func (r *AddBookCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultAddBookOptions()
options := armaria.DefaultAddBookOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}
Expand All @@ -124,7 +123,7 @@ func (r *AddBookCmd) Run(ctx *Context) error {
options.WithTags(r.Tag)
}

book, err := armariaapi.AddBook(r.URL, options)
book, err := armaria.AddBook(r.URL, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -150,15 +149,15 @@ type AddFolderCmd struct {
func (r *AddFolderCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultAddFolderOptions()
options := armaria.DefaultAddFolderOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}
if r.Folder != nil {
options.WithParentID(*r.Folder)
}

book, err := armariaapi.AddFolder(r.Name, options)
book, err := armaria.AddFolder(r.Name, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -184,12 +183,12 @@ type AddTagsCmd struct {
func (r *AddTagsCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultAddTagsOptions()
options := armaria.DefaultAddTagsOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

book, err := armariaapi.AddTags(r.ID, r.Tag, options)
book, err := armaria.AddTags(r.ID, r.Tag, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down Expand Up @@ -226,7 +225,7 @@ func (r *ListAllCmd) Run(ctx *Context) error {
return nil
}

options := armariaapi.DefaultListBooksOptions()
options := armaria.DefaultListBooksOptions()
options.WithFolders(true)
options.WithBooks(true)
if ctx.DB != nil {
Expand Down Expand Up @@ -257,7 +256,7 @@ func (r *ListAllCmd) Run(ctx *Context) error {
options.WithFirst(*r.First)
}

books, err := armariaapi.ListBooks(options)
books, err := armaria.ListBooks(options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down Expand Up @@ -294,7 +293,7 @@ func (r *ListBooksCmd) Run(ctx *Context) error {
return nil
}

options := armariaapi.DefaultListBooksOptions()
options := armaria.DefaultListBooksOptions()
options.WithFolders(false)
options.WithBooks(true)
if ctx.DB != nil {
Expand Down Expand Up @@ -325,7 +324,7 @@ func (r *ListBooksCmd) Run(ctx *Context) error {
options.WithFirst(*r.First)
}

books, err := armariaapi.ListBooks(options)
books, err := armaria.ListBooks(options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down Expand Up @@ -362,7 +361,7 @@ func (r *ListFoldersCmd) Run(ctx *Context) error {
return nil
}

options := armariaapi.DefaultListBooksOptions()
options := armaria.DefaultListBooksOptions()
options.WithFolders(true)
options.WithBooks(false)
if ctx.DB != nil {
Expand Down Expand Up @@ -393,7 +392,7 @@ func (r *ListFoldersCmd) Run(ctx *Context) error {
options.WithFirst(*r.First)
}

books, err := armariaapi.ListBooks(options)
books, err := armaria.ListBooks(options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -420,7 +419,7 @@ type ListTagsCmd struct {
func (r *ListTagsCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultListTagsOptions()
options := armaria.DefaultListTagsOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}
Expand All @@ -437,7 +436,7 @@ func (r *ListTagsCmd) Run(ctx *Context) error {
options.WithFirst(*r.First)
}

tags, err := armariaapi.ListTags(options)
tags, err := armaria.ListTags(options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -461,12 +460,12 @@ type ListParentNamesCmd struct {
func (r *ListParentNamesCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultGetParentNameOptions()
options := armaria.DefaultGetParentNameOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

names, err := armariaapi.GetParentNames(r.ID, options)
names, err := armaria.GetParentNames(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down Expand Up @@ -511,7 +510,7 @@ func (r *UpdateBookCmd) Run(ctx *Context) error {
return nil
}

options := armariaapi.DefaultUpdateBookOptions()
options := armaria.DefaultUpdateBookOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}
Expand Down Expand Up @@ -540,7 +539,7 @@ func (r *UpdateBookCmd) Run(ctx *Context) error {
options.WithOrderAfter(*r.After)
}

book, err := armariaapi.UpdateBook(r.ID, options)
book, err := armaria.UpdateBook(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down Expand Up @@ -576,7 +575,7 @@ func (r *UpdateFolderCmd) Run(ctx *Context) error {
return nil
}

options := armariaapi.DefaultUpdateFolderOptions()
options := armaria.DefaultUpdateFolderOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}
Expand All @@ -596,7 +595,7 @@ func (r *UpdateFolderCmd) Run(ctx *Context) error {
options.WithOrderAfter(*r.After)
}

book, err := armariaapi.UpdateFolder(r.ID, options)
book, err := armaria.UpdateFolder(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -620,12 +619,12 @@ type RemoveBookCmd struct {
func (r *RemoveBookCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultRemoveBookOptions()
options := armaria.DefaultRemoveBookOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

err := armariaapi.RemoveBook(r.ID, options)
err := armaria.RemoveBook(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -648,12 +647,12 @@ type RemoveFolderCmd struct {
func (r *RemoveFolderCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultRemoveFolderOptions()
options := armaria.DefaultRemoveFolderOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

err := armariaapi.RemoveFolder(r.ID, options)
err := armaria.RemoveFolder(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -678,12 +677,12 @@ type RemoveTagsCmd struct {
func (r *RemoveTagsCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultRemoveTagsOptions()
options := armaria.DefaultRemoveTagsOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

book, err := armariaapi.RemoveTags(r.ID, r.Tag, options)
book, err := armaria.RemoveTags(r.ID, r.Tag, options)

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
Expand All @@ -708,12 +707,12 @@ type GetAllCmd struct {
func (r *GetAllCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultGetBookOptions()
options := armaria.DefaultGetBookOptions()
if ctx.DB != nil {
options.WithDB(*ctx.DB)
}

book, err := armariaapi.GetBook(r.ID, options)
book, err := armaria.GetBook(r.ID, options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand All @@ -736,7 +735,7 @@ type GetDBConfigCmd struct {
func (r *GetDBConfigCmd) Run(ctx *Context) error {
start := time.Now()

config, err := armariaapi.GetConfig()
config, err := armaria.GetConfig()

if err != nil && !errors.Is(err, armaria.ErrConfigMissing) {
formatError(ctx.Writer, ctx.Formatter, err)
Expand All @@ -761,7 +760,7 @@ type SetDBConfigCmd struct {
func (r *SetDBConfigCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.UpdateConfig(func(config *armaria.Config) {
err := armaria.UpdateConfig(func(config *armaria.Config) {
config.DB = r.DB
})

Expand All @@ -786,7 +785,7 @@ type InstallFirefoxManifestCmd struct {
func (r *InstallFirefoxManifestCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.InstallManifestFirefox()
err := armaria.InstallManifestFirefox()

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
Expand All @@ -809,7 +808,7 @@ type InstallChromeManifestCmd struct {
func (r *InstallChromeManifestCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.InstallManifestChrome()
err := armaria.InstallManifestChrome()

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
Expand All @@ -832,7 +831,7 @@ type InstallChromiumManifestCmd struct {
func (r *InstallChromiumManifestCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.InstallManifestChromium()
err := armaria.InstallManifestChromium()

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
Expand Down Expand Up @@ -869,7 +868,7 @@ type QueryCmd struct {
func (r *QueryCmd) Run(ctx *Context) error {
start := time.Now()

options := armariaapi.DefaultListBooksOptions()
options := armaria.DefaultListBooksOptions()
options.WithFolders(true)
options.WithBooks(true)
if ctx.DB != nil {
Expand All @@ -878,7 +877,7 @@ func (r *QueryCmd) Run(ctx *Context) error {
options.WithFirst(r.First)
options.WithQuery(r.Query)

books, err := armariaapi.ListBooks(options)
books, err := armaria.ListBooks(options)
if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/internal/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/jonathanhope/armaria/internal/null"
"github.com/jonathanhope/armaria/pkg/model"
"github.com/jonathanhope/armaria/pkg"
"github.com/nathan-fiscaletti/consolesize-go"
"github.com/samber/lo"
)
Expand Down
11 changes: 5 additions & 6 deletions cmd/cli/test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
"github.com/google/uuid"
"github.com/jonathanhope/armaria/cmd/cli/internal"
"github.com/jonathanhope/armaria/internal/null"
"github.com/jonathanhope/armaria/pkg/api"
"github.com/jonathanhope/armaria/pkg/model"
"github.com/jonathanhope/armaria/pkg"
)

// invokeCli runs the Armaria CLI with the provided args.
Expand Down Expand Up @@ -114,7 +113,7 @@ func insert(args insertArgs) error {

var book armaria.Book
if !isFolder {
options := armariaapi.DefaultAddBookOptions()
options := armaria.DefaultAddBookOptions()
options.WithDB(args.db)
if parentID.Valid {
options.WithParentID(parentID.String)
Expand All @@ -129,18 +128,18 @@ func insert(args insertArgs) error {
options.WithTags(tags)
}

book, err = armariaapi.AddBook(URL.String, options)
book, err = armaria.AddBook(URL.String, options)
if err != nil {
return err
}
} else {
options := armariaapi.DefaultAddFolderOptions()
options := armaria.DefaultAddFolderOptions()
options.WithDB(args.db)
if parentID.Valid {
options.WithParentID(parentID.String)
}

book, err = armariaapi.AddFolder(name, options)
book, err = armaria.AddFolder(name, options)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit baa6bd0

Please sign in to comment.