Skip to content

Commit

Permalink
chore: rename programa to app
Browse files Browse the repository at this point in the history
  • Loading branch information
marianozunino committed Aug 21, 2024
1 parent ba1ee02 commit 767ee05
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 63 deletions.
18 changes: 9 additions & 9 deletions cmd/dmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ THE SOFTWARE.
package cmd

import (
"github.com/marianozunino/sdm-ui/internal/program"
"github.com/marianozunino/sdm-ui/internal/app"
"github.com/spf13/cobra"
)

Expand All @@ -35,19 +35,19 @@ var dmenuCmd = &cobra.Command{
Short: "Opens dmenu with available data sources",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
var commandOption program.ProgramOption
var commandOption app.AppOption

if useWofi {
commandOption = program.WithCommand(program.Wofi)
commandOption = app.WithCommand(app.Wofi)
} else {
commandOption = program.WithCommand(program.Rofi)
commandOption = app.WithCommand(app.Rofi)
}

program.NewProgram(
program.WithAccount(confData.Email),
program.WithVerbose(confData.Verbose),
program.WithDbPath(confData.DBPath),
program.WithBlacklist(confData.BalcklistPatterns),
app.Newapp(
app.WithAccount(confData.Email),
app.WithVerbose(confData.Verbose),
app.WithDbPath(confData.DBPath),
app.WithBlacklist(confData.BalcklistPatterns),
commandOption,
).DMenu()

Expand Down
12 changes: 6 additions & 6 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package cmd
import (
"os"

"github.com/marianozunino/sdm-ui/internal/program"
"github.com/marianozunino/sdm-ui/internal/app"
"github.com/spf13/cobra"
)

Expand All @@ -34,11 +34,11 @@ var listCmd = &cobra.Command{
Short: "List SDM resources",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
program.NewProgram(
program.WithAccount(confData.Email),
program.WithVerbose(confData.Verbose),
program.WithDbPath(confData.DBPath),
program.WithBlacklist(confData.BalcklistPatterns),
app.Newapp(
app.WithAccount(confData.Email),
app.WithVerbose(confData.Verbose),
app.WithDbPath(confData.DBPath),
app.WithBlacklist(confData.BalcklistPatterns),
).List(os.Stdout)
},
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ THE SOFTWARE.
package cmd

import (
"github.com/marianozunino/sdm-ui/internal/program"
"github.com/marianozunino/sdm-ui/internal/app"
"github.com/spf13/cobra"
)

Expand All @@ -32,11 +32,11 @@ var syncCmd = &cobra.Command{
Short: "Syncronizes the internal cache",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
program.NewProgram(
program.WithAccount(confData.Email),
program.WithVerbose(confData.Verbose),
program.WithDbPath(confData.DBPath),
program.WithBlacklist(confData.BalcklistPatterns),
app.Newapp(
app.WithAccount(confData.Email),
app.WithVerbose(confData.Verbose),
app.WithDbPath(confData.DBPath),
app.WithBlacklist(confData.BalcklistPatterns),
).Sync()
},
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ THE SOFTWARE.
package cmd

import (
"github.com/marianozunino/sdm-ui/internal/program"
"github.com/marianozunino/sdm-ui/internal/app"
"github.com/spf13/cobra"
)

Expand All @@ -32,10 +32,10 @@ var wipeCmd = &cobra.Command{
Short: "Wipe the SDM UI cache db",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
program.NewProgram(
program.WithAccount(confData.Email),
program.WithVerbose(confData.Verbose),
program.WithDbPath(confData.DBPath),
app.Newapp(
app.WithAccount(confData.Email),
app.WithVerbose(confData.Verbose),
app.WithDbPath(confData.DBPath),
).WipeCache()
},
}
Expand Down
38 changes: 19 additions & 19 deletions internal/program/program.go → internal/app/app.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"fmt"
Expand All @@ -14,7 +14,7 @@ import (
"github.com/rs/zerolog/log"
)

type Program struct {
type App struct {
account string

db *storage.Storage
Expand All @@ -25,41 +25,41 @@ type Program struct {
blacklistPatterns []string
}

type ProgramOption func(*Program)
type AppOption func(*App)

func WithAccount(account string) ProgramOption {
return func(p *Program) {
func WithAccount(account string) AppOption {
return func(p *App) {
log.Debug().Msgf("Using account: %s", account)
p.account = account
}
}

func WithVerbose(verbose bool) ProgramOption {
func WithVerbose(verbose bool) AppOption {
logger.ConfigureLogger(verbose)
return func(p *Program) {}
return func(p *App) {}
}

func WithDbPath(dbPath string) ProgramOption {
return func(p *Program) {
func WithDbPath(dbPath string) AppOption {
return func(p *App) {
p.dbPath = dbPath
}
}

func WithBlacklist(patterns []string) ProgramOption {
return func(p *Program) {
func WithBlacklist(patterns []string) AppOption {
return func(p *App) {
p.blacklistPatterns = patterns
}
}

func WithCommand(command DMenuCommand) ProgramOption {
return func(p *Program) {
func WithCommand(command DMenuCommand) AppOption {
return func(p *App) {
p.dmenuCommand = command
}
}

func NewProgram(opts ...ProgramOption) *Program {
func Newapp(opts ...AppOption) *App {

p := &Program{
p := &App{
sdmWrapper: sdm.SDMClient{Exe: "sdm"},
dbPath: xdg.DataHome,
dmenuCommand: Rofi,
Expand All @@ -83,7 +83,7 @@ func NewProgram(opts ...ProgramOption) *Program {
return p
}

func (p *Program) validateAccount() error {
func (p *App) validateAccount() error {
status, err := p.sdmWrapper.Ready()
if err != nil {
return err
Expand Down Expand Up @@ -130,7 +130,7 @@ func ellipsize(s string, maxLen int) string {
return s[:maxLen] + "..."
}

func (p *Program) retryCommand(command func() error) error {
func (p *App) retryCommand(command func() error) error {
err := command()

if err == nil {
Expand Down Expand Up @@ -158,7 +158,7 @@ func (p *Program) retryCommand(command func() error) error {
}
}

func (p *Program) handleUnauthorized(command func() error) error {
func (p *App) handleUnauthorized(command func() error) error {
notify.Notify("SDM CLI", "Authenticating... 🔐", "", "")

password, err := p.retrievePassword()
Expand All @@ -180,7 +180,7 @@ func (p *Program) handleUnauthorized(command func() error) error {
return command()
}

func (p *Program) handleInvalidCredentials(err error) error {
func (p *App) handleInvalidCredentials(err error) error {
notify.Notify("SDM CLI", "Authentication error 🔐", "Invalid credentials", "")
p.keyring.DeleteSecret(p.account)
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"fmt"
Expand Down
12 changes: 6 additions & 6 deletions internal/program/dmenu.go → internal/app/dmenu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"bytes"
Expand Down Expand Up @@ -27,7 +27,7 @@ func (d DMenuCommand) String() string {
return string(d)
}

func (p *Program) DMenu() error {
func (p *App) DMenu() error {

bytesOut := new(bytes.Buffer)

Expand All @@ -45,15 +45,15 @@ func (p *Program) DMenu() error {
return p.handleSelectedEntry(selectedEntry)
}

func (p *Program) createEntriesFromBuffer(buf *bytes.Buffer) []*entry.Entry {
func (p *App) createEntriesFromBuffer(buf *bytes.Buffer) []*entry.Entry {
var entries []*entry.Entry
for _, line := range bytes.Split(buf.Bytes(), []byte("\n")) {
entries = append(entries, entry.New(string(line)))
}
return entries
}

func (p *Program) getSelectionFromDmenu(entries []*entry.Entry) (string, error) {
func (p *App) getSelectionFromDmenu(entries []*entry.Entry) (string, error) {
d := dmenu.New(
dmenu.WithPrompt("Select Data Source"),
dmenu.WithEntries(entries...),
Expand All @@ -70,7 +70,7 @@ func (p *Program) getSelectionFromDmenu(entries []*entry.Entry) (string, error)
return s, nil
}

func (p *Program) handleSelectedEntry(selectedEntry string) error {
func (p *App) handleSelectedEntry(selectedEntry string) error {
fields := strings.Fields(selectedEntry)

if len(fields) < 2 {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *Program) handleSelectedEntry(selectedEntry string) error {
return p.Sync()
}

func (p *Program) notifyDataSourceConnected(ds storage.DataSource) {
func (p *App) notifyDataSourceConnected(ds storage.DataSource) {
title := "Data Source Connected 🔌"
message := fmt.Sprintf("%s\n📋 <b>%s</b>", ds.Name, ds.Address)

Expand Down
6 changes: 3 additions & 3 deletions internal/program/list.go → internal/app/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"io"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log"
)

func (p *Program) List(w io.Writer) error {
func (p *App) List(w io.Writer) error {
dataSources, err := p.db.RetrieveDatasources()

if err != nil {
Expand Down Expand Up @@ -40,7 +40,7 @@ func (p *Program) List(w io.Writer) error {
return nil
}

func (p *Program) applyBlacklist(dataSources []storage.DataSource) []storage.DataSource {
func (p *App) applyBlacklist(dataSources []storage.DataSource) []storage.DataSource {
var filteredDataSources []storage.DataSource

if len(p.blacklistPatterns) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/program/parser.go → internal/app/parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"encoding/json"
Expand Down
6 changes: 3 additions & 3 deletions internal/program/password.go → internal/app/password.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package program
package app

import (
"fmt"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/rs/zerolog/log"
)

func (p *Program) retrievePassword() (string, error) {
func (p *App) retrievePassword() (string, error) {
log.Debug().Msg("Retrieving password...")
password, err := p.keyring.GetSecret(p.account)
if err != nil {
Expand All @@ -31,7 +31,7 @@ func (p *Program) retrievePassword() (string, error) {
return password, nil
}

func (p *Program) askForPassword() (string, error) {
func (p *App) askForPassword() (string, error) {
log.Debug().Msg("Prompting for password...")
_, pwd, err := zenity.Password(zenity.Title("Type your SDM password"))
return pwd, err
Expand Down
4 changes: 2 additions & 2 deletions internal/program/sync.go → internal/app/sync.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package program
package app

import (
"bytes"

"github.com/rs/zerolog/log"
)

func (p *Program) Sync() error {
func (p *App) Sync() error {
log.Debug().Msg("Syncing...")
statusesBuffer := new(bytes.Buffer)

Expand Down
4 changes: 2 additions & 2 deletions internal/program/wipe.go → internal/app/wipe.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package program
package app

import (
"github.com/rs/zerolog/log"
)

func (p *Program) WipeCache() error {
func (p *App) WipeCache() error {
log.Debug().Msg("Wiping cache...")

err := p.db.Wipe()
Expand Down

0 comments on commit 767ee05

Please sign in to comment.