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
4 changes: 2 additions & 2 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"context"
"fmt"
"log/slog"
"os"
"time"

"github.com/malamtime/cli/commands"
"github.com/malamtime/cli/model"
"github.com/sirupsen/logrus"
"github.com/uptrace/uptrace-go/uptrace"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -110,7 +110,7 @@ func main() {
}
err = app.Run(os.Args)
if err != nil {
logrus.Errorln(err)
slog.Error("CLI error", slog.Any("err", err))
}
commands.CloseLogger()
}
2 changes: 1 addition & 1 deletion cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {
defer syncCircuitBreakerService.Stop()
}

go daemon.SocketTopicProccessor(msg)
go daemon.SocketTopicProcessor(msg)

// Start CCUsage service if enabled (v1 - ccusage CLI based)
if cfg.CCUsage != nil && cfg.CCUsage.Enabled != nil && *cfg.CCUsage.Enabled {
Expand Down
23 changes: 11 additions & 12 deletions commands/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package commands

import (
"context"
"log/slog"
"os"
"strings"

"github.com/malamtime/cli/model"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -51,25 +51,24 @@ func importAliases(c *cli.Context) error {
ctx, span := commandTracer.Start(c.Context, "alias-import", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
SetupLogger(os.ExpandEnv("$HOME/" + model.COMMAND_BASE_STORAGE_FOLDER))
logrus.SetLevel(logrus.TraceLevel)

isFullyRefresh := c.Bool("fully-refresh")
span.SetAttributes(attribute.Bool("fully-refresh", isFullyRefresh))

zshConfigFile, err := expandPath(c.String("zsh-config"))
if err != nil {
logrus.Errorln(err)
slog.Error("failed to expand zsh config path", slog.Any("err", err))
return err
}
fishConfigFile, err := expandPath(c.String("fish-config"))
if err != nil {
logrus.Errorln(err)
slog.Error("failed to expand fish config path", slog.Any("err", err))
return err
}

config, err := configService.ReadConfigFile(ctx)
if err != nil {
logrus.Errorln(err)
slog.Error("failed to read config file", slog.Any("err", err))
return err
}

Expand All @@ -81,10 +80,10 @@ func importAliases(c *cli.Context) error {
if _, err := os.Stat(zshConfigFile); err == nil {
aliases, err := parseZshAliases(ctx, zshConfigFile)
if err != nil {
logrus.Errorln("Failed to parse zsh aliases:", err)
slog.Error("Failed to parse zsh aliases", slog.Any("err", err))
return err
}
logrus.Traceln("Found aliases in zsh configuration", len(aliases))
slog.Debug("Found aliases in zsh configuration", slog.Int("count", len(aliases)))
err = model.SendAliasesToServer(
ctx,
mainEndpoint,
Expand All @@ -94,18 +93,18 @@ func importAliases(c *cli.Context) error {
zshConfigFile,
)
if err != nil {
logrus.Errorln("Failed to send aliases to server:", err)
slog.Error("Failed to send aliases to server", slog.Any("err", err))
return err
}
}

if _, err := os.Stat(fishConfigFile); err == nil {
aliases, err := parseFishAliases(ctx, fishConfigFile)
if err != nil {
logrus.Errorln("Failed to parse fish aliases:", err)
slog.Error("Failed to parse fish aliases", slog.Any("err", err))
return err
}
logrus.Traceln("Found aliases in fish configuration", len(aliases))
slog.Debug("Found aliases in fish configuration", slog.Int("count", len(aliases)))
err = model.SendAliasesToServer(
ctx,
mainEndpoint,
Expand All @@ -115,12 +114,12 @@ func importAliases(c *cli.Context) error {
fishConfigFile,
)
if err != nil {
logrus.Errorln("Failed to send aliases to server:", err)
slog.Error("Failed to send aliases to server", slog.Any("err", err))
return err
}
}

logrus.Infoln("Successfully imported aliases")
slog.Info("Successfully imported aliases")
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions commands/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"context"
"fmt"
"log/slog"
"os"
"time"

Expand All @@ -11,7 +12,6 @@ import (
"github.com/malamtime/cli/model"
"github.com/pelletier/go-toml/v2"
"github.com/pkg/browser"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -102,7 +102,7 @@ func ApplyTokenByHandshake(_ctx context.Context, config model.ShellTimeConfig) (
feLink := fmt.Sprintf("%s/cli/integration?hid=%s", config.WebEndpoint, hid)

if err := browser.OpenURL(feLink); err != nil {
logrus.Errorln(err)
slog.Error("failed to open browser", slog.Any("err", err))
}

color.Green.Println(fmt.Sprintf("Open %s to continue", feLink))
Expand Down
30 changes: 15 additions & 15 deletions commands/dotfiles_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package commands

import (
"fmt"
"log/slog"
"os"

"github.com/malamtime/cli/model"
"github.com/pterm/pterm"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -37,7 +37,7 @@ func printPullResults(result map[model.DotfileAppName][]dotfilePullFileResult, d

// No files to process
if totalProcessed == 0 && totalFailed == 0 && totalSkipped == 0 {
logrus.Infoln("No dotfiles found to process")
slog.Info("No dotfiles found to process")
pterm.Info.Println("No dotfiles to process")
return
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func printPullResults(result map[model.DotfileAppName][]dotfilePullFileResult, d
}

// Log for debugging
logrus.Infof("Pull complete - Processed: %d, Skipped: %d, Failed: %d", totalProcessed, totalSkipped, totalFailed)
slog.Info("Pull complete", slog.Int("processed", totalProcessed), slog.Int("skipped", totalSkipped), slog.Int("failed", totalFailed))
}

func pullDotfiles(c *cli.Context) error {
Expand All @@ -131,7 +131,7 @@ func pullDotfiles(c *cli.Context) error {

config, err := configService.ReadConfigFile(ctx)
if err != nil {
logrus.Errorln(err)
slog.Error("failed to read config file", slog.Any("err", err))
return err
}

Expand Down Expand Up @@ -169,15 +169,15 @@ func pullDotfiles(c *cli.Context) error {
}

// Fetch dotfiles from server
logrus.Infof("Fetching dotfiles from server...")
slog.Info("Fetching dotfiles from server...")
resp, err := model.FetchDotfilesFromServer(ctx, mainEndpoint, filter)
if err != nil {
logrus.Errorln("Failed to fetch dotfiles from server:", err)
slog.Error("Failed to fetch dotfiles from server", slog.Any("err", err))
return err
}

if resp == nil || len(resp.Data.FetchUser.Dotfiles.Apps) == 0 {
logrus.Infoln("No dotfiles found on server")
slog.Info("No dotfiles found on server")
fmt.Println("\n📭 No dotfiles found on server")
return nil
}
Expand All @@ -188,18 +188,18 @@ func pullDotfiles(c *cli.Context) error {
appName := model.DotfileAppName(appData.App)
app, exists := appHandlers[appName]
if !exists {
logrus.Warnf("Unknown app type: %s", appData.App)
slog.Warn("Unknown app type", slog.String("app", appData.App))
continue
}

logrus.Infof("Processing %s dotfiles...", appData.App)
slog.Info("Processing dotfiles...", slog.String("app", appData.App))

// Collect files to process for this app
filesToProcess := make(map[string]string)

for _, file := range appData.Files {
if len(file.Records) == 0 {
logrus.Debugf("No records found for %s", file.Path)
slog.Debug("No records found", slog.String("path", file.Path))
continue
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func pullDotfiles(c *cli.Context) error {
// Check which files are different
equalityMap, err := app.IsEqual(ctx, filesToProcess)
if err != nil {
logrus.Warnf("Failed to check file equality for %s: %v", appData.App, err)
slog.Warn("Failed to check file equality", slog.String("app", appData.App), slog.Any("err", err))
}

// Filter out files that are already equal
Expand All @@ -255,7 +255,7 @@ func pullDotfiles(c *cli.Context) error {

for path, content := range filesToProcess {
if isEqual, exists := equalityMap[path]; exists && isEqual {
logrus.Debugf("Skipping %s - content is identical", path)
slog.Debug("Skipping - content is identical", slog.String("path", path))
result[appName] = append(result[appName], dotfilePullFileResult{
path: path,
isSkipped: true,
Expand All @@ -267,20 +267,20 @@ func pullDotfiles(c *cli.Context) error {
}

if len(filesToUpdate) == 0 {
logrus.Infof("All %s files are up to date", appData.App)
slog.Info("All files are up to date", slog.String("app", appData.App))
continue
}

results := make([]dotfilePullFileResult, 0)

// Backup files that will be modified (handles dry-run internally)
if err := app.Backup(ctx, pathsToActuallyBackup, dryRun); err != nil {
logrus.Warnf("Failed to backup files for %s: %v", appData.App, err)
slog.Warn("Failed to backup files", slog.String("app", appData.App), slog.Any("err", err))
}

// Save the updated files (handles dry-run internally)
if err := app.Save(ctx, filesToUpdate, dryRun); err != nil {
logrus.Errorf("Failed to save files for %s: %v", appData.App, err)
slog.Error("Failed to save files", slog.String("app", appData.App), slog.Any("err", err))
for f := range filesToUpdate {
results = append(results, dotfilePullFileResult{
path: f,
Expand Down
18 changes: 9 additions & 9 deletions commands/dotfiles_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package commands

import (
"fmt"
"log/slog"
"os"

"github.com/malamtime/cli/model"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand All @@ -21,7 +21,7 @@ func pushDotfiles(c *cli.Context) error {

config, err := configService.ReadConfigFile(ctx)
if err != nil {
logrus.Errorln(err)
slog.Error("failed to read config file", slog.Any("err", err))
return err
}

Expand Down Expand Up @@ -66,39 +66,39 @@ func pushDotfiles(c *cli.Context) error {
if app, ok := appMap[appName]; ok {
selectedApps = append(selectedApps, app)
} else {
logrus.Warnf("Unknown app: %s", appName)
slog.Warn("Unknown app", slog.String("app", appName))
}
}
}

// Collect all dotfiles
var allDotfiles []model.DotfileItem
for _, app := range selectedApps {
logrus.Infof("Collecting dotfiles for %s", app.Name())
slog.Info("Collecting dotfiles", slog.String("app", app.Name()))
dotfiles, err := app.CollectDotfiles(ctx)
if err != nil {
logrus.Errorf("Failed to collect dotfiles for %s: %v", app.Name(), err)
slog.Error("Failed to collect dotfiles", slog.String("app", app.Name()), slog.Any("err", err))
continue
}
allDotfiles = append(allDotfiles, dotfiles...)
}

if len(allDotfiles) == 0 {
logrus.Infoln("No dotfiles found to push")
slog.Info("No dotfiles found to push")
return nil
}

// Send to server
logrus.Infof("Pushing %d dotfiles to server", len(allDotfiles))
slog.Info("Pushing dotfiles to server", slog.Int("count", len(allDotfiles)))
userID, err := model.SendDotfilesToServer(ctx, mainEndpoint, allDotfiles)
if err != nil {
logrus.Errorln("Failed to send dotfiles to server:", err)
slog.Error("Failed to send dotfiles to server", slog.Any("err", err))
return err
}

// Generate web link for managing dotfiles
webLink := fmt.Sprintf("%s/users/%d/settings/dotfiles", config.WebEndpoint, userID)
logrus.Infof("Successfully pushed dotfiles. Manage them at: %s", webLink)
slog.Info("Successfully pushed dotfiles", slog.String("webLink", webLink))
fmt.Printf("\n✅ Successfully pushed %d dotfiles to server\n", len(allDotfiles))
fmt.Printf("📁 Manage your dotfiles at: %s\n", webLink)

Expand Down
Loading
Loading