Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds config #1

Merged
merged 2 commits into from
Dec 18, 2023
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
# Go workspace file
go.work
bin/
dotfiles
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME := dotfiles-cli
APP_NAME := dotfiles

GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/bin
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# dotfiles-cli
# dotfiles CLI

This is my personal [dotfiles](/~https://github.com/pablobfonseca/dotfiles.git) installer

## Getting started
```shell
$ dotfiles-cli
dotfiles-cli is a CLI tool to install dotfiles from a git repository.
$ dotfiles
dotfiles is a CLI tool to install dotfiles from a git repository.

Usage:
dotfiles-cli [command]
dotfiles [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
Expand All @@ -18,8 +18,8 @@ Available Commands:
update Update the dotfiles

Flags:
-h, --help help for dotfiles-cli
-h, --help help for dotfiles
-t, --toggle Help message for toggle

Use "dotfiles-cli [command] --help" for more information about a command.
Use "dotfiles [command] --help" for more information about a command.
```
14 changes: 7 additions & 7 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
"github.com/vbauerster/mpb/v7"

dotfiles "github.com/pablobfonseca/dotfiles-cli/src/installers"
dotfiles "github.com/pablobfonseca/dotfiles/src/installers"
)

var installCmd = &cobra.Command{
Expand All @@ -29,10 +29,10 @@ var installCmd = &cobra.Command{
installAll(p)
}
if nvim {
dotfiles.InstallNvim(p)
dotfiles.InstallNvim(p, verbose)
}
if emacs {
dotfiles.InstallEmacs(p)
dotfiles.InstallEmacs(p, verbose)
}
if zsh {
dotfiles.InstallZsh(p)
Expand All @@ -43,11 +43,11 @@ var installCmd = &cobra.Command{
}

func installAll(p *mpb.Progress) {
dotfiles.CloneRepo(p)
dotfiles.InstallHomebrew(p)
dotfiles.InstallNvim(p)
dotfiles.CloneRepo(p, verbose)
dotfiles.InstallHomebrew(p, verbose)
dotfiles.InstallNvim(p, verbose)
dotfiles.InstallZsh(p)
dotfiles.InstallEmacs(p)
dotfiles.InstallEmacs(p, verbose)
}

func init() {
Expand Down
50 changes: 40 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ package cmd

import (
"os"
"path"

tea "github.com/charmbracelet/bubbletea"
"github.com/pablobfonseca/dotfiles/src/utils"
"github.com/pablobfonseca/dotfiles/src/utils/prompts"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "dotfiles-cli",
Use: "dotfiles",
Short: "Install dotfiles from a git repository",
Long: `dotfiles-cli is a CLI tool to install dotfiles from a git repository.`,
Long: `dotfiles is a CLI tool to install dotfiles from a git repository.`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -25,15 +30,40 @@ func Execute() {
}
}

var cfgFile = ""
var verbose bool

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// cfgFile := ""
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dotfiles/config.toml)")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/config/dotfiles-cli/config.yaml)")
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
if err != nil {
utils.ErrorMessage("Something went wrong", err)
}

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
viper.AddConfigPath(path.Join(home, ".dotfiles/"))
viper.SetConfigType("toml")
viper.SetConfigName("config")
}

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
p := tea.NewProgram(prompts.ConfigPrompt())

if _, err := p.Run(); err != nil {
utils.ErrorMessage("[Config prompt error]: Something went wrong", err)
}

} else {
utils.ErrorMessage("Something went wrong", err)
}
}
}
21 changes: 12 additions & 9 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
"github.com/spf13/cobra"
"github.com/vbauerster/mpb/v7"

dotfiles "github.com/pablobfonseca/dotfiles-cli/src/installers"
dotfiles "github.com/pablobfonseca/dotfiles/src/installers"
)

var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Uninstall the dotfiles",
Long: `Uninstall the dotfiles. You can uninstall all the dotfiles or just some of them.
Example: dotfiles uninstall --all
dotfiles uninstall --nvim
Example: dotfiles uninstall --nvim
dotfiles uninstall --emacs
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -29,26 +28,30 @@ var uninstallCmd = &cobra.Command{
uninstallAll(p)
}
if nvim {
dotfiles.UninstallNvim(p)
dotfiles.UninstallNvim(uninstallApp, p, verbose)
}
if emacs {
dotfiles.UninstallEmacs(p)
dotfiles.UninstallEmacs(uninstallApp, p, verbose)
}

p.Wait()
},
}

func uninstallAll(p *mpb.Progress) {
dotfiles.DeleteRepo(p)
dotfiles.UninstallNvim(p)
dotfiles.UninstallEmacs(p)
dotfiles.DeleteRepo(p, verbose)
dotfiles.UninstallNvim(uninstallApp, p, verbose)
dotfiles.UninstallEmacs(uninstallApp, p, verbose)
}

var uninstallApp bool

func init() {
rootCmd.AddCommand(uninstallCmd)

uninstallCmd.Flags().BoolP("all", "a", false, "Uninstall all the dotfiles")
uninstallCmd.Flags().BoolVarP(&uninstallApp, "prune", "p", false, "Also uninstall the app")

uninstallCmd.Flags().BoolP("all", "a", false, "Uninstall all dotfiles")
uninstallCmd.Flags().BoolP("nvim", "n", false, "Uninstall nvim files")
uninstallCmd.Flags().BoolP("emacs", "e", false, "Uninstall emacs files")
}
6 changes: 3 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
updaters "github.com/pablobfonseca/dotfiles-cli/src/updaters"
updaters "github.com/pablobfonseca/dotfiles/src/updaters"
"github.com/spf13/cobra"
"github.com/vbauerster/mpb/v7"
)
Expand All @@ -21,11 +21,11 @@ var updateCmd = &cobra.Command{
brew, _ := cmd.Flags().GetBool("brew")

if nvim {
updaters.UpdateNvim(p)
updaters.UpdateNvim(p, verbose)
}

if brew {
updaters.UpdateBrew(p)
updaters.UpdateBrew(p, verbose)
}

p.Wait()
Expand Down
41 changes: 37 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
module github.com/pablobfonseca/dotfiles-cli
module github.com/pablobfonseca/dotfiles

go 1.21.5

require (
github.com/charmbracelet/bubbles v0.17.1
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/enescakir/emoji v1.0.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.18.1
github.com/vbauerster/mpb/v7 v7.5.3
)

require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/enescakir/emoji v1.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading