Skip to content

Commit

Permalink
Feat auto (#25)
Browse files Browse the repository at this point in the history
* add(cli): #24 - automatic setup

* upd(auto): #24 - brew install

* upd(auto): #24 - brew install

* fix(auto): #24 - fix brew cmd

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages

* fix(auto): #24 - fix packages
  • Loading branch information
alexandre-delaloy authored Mar 7, 2022
1 parent ca17813 commit 138c225
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ setup-env: ## Copy sample files
run: ## Up the docker-compose without cache or orphans
go run cmd/flamin-go/main.go

build: ## Up the docker-compose without cache or orphans
go build cmd/flamin-go/main.go

stop: ## Down the docker-compose
docker-compose down

Expand Down
87 changes: 61 additions & 26 deletions cmd/flamin-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ func runConfirmPrompt(mode core.Mode, task core.Task, action core.Action) {
}
}

func runAuto(mode core.Mode) {
choice := chalk.Cyan.NewStyle().WithBackground(chalk.ResetColor).WithTextStyle(chalk.Bold).Style(mode.Description)

helpers.ClearPrompt()
fmt.Print("Mode: ", chalk.Red, mode.Name, chalk.Reset, "\n")
fmt.Print("You're about to: ", choice, "\n")

confirmPrompt := promptui.Prompt{
Label: "Continue",
Default: "y",
IsConfirm: true,
}

result, err := confirmPrompt.Run()
helpers.ExitOnError("confirmPrompt failed:", err)
if result == "" || result == "Y" || result == "y" {
execAction("packages/apt")
execAction("packages/brew")

execAction("zsh/omz")
execAction("zsh/plugins")
execAction("zsh/prompt")

execAction("dotfiles/sync")
execAction("dotfiles/rc")

execAction("clis/docker")
execAction("clis/k8s")
}
}

func run() {

helpers.ClearPrompt()
Expand All @@ -74,34 +105,38 @@ func run() {
}
h, _, err := modesPrompt.Run()
helpers.ClosePrompt(err)

mode := core.Modes[h]

taskPrompt := promptui.Select{
Label: "[choose]: task category",
Items: core.Tasks,
Templates: core.TaskTpl,
Size: 10,
Searcher: searcher(),
Stdout: &helpers.BellSkipper{},
if h == 0 {

taskPrompt := promptui.Select{
Label: "[choose]: task category",
Items: core.Tasks,
Templates: core.TaskTpl,
Size: 10,
Searcher: searcher(),
Stdout: &helpers.BellSkipper{},
}
i, _, err := taskPrompt.Run()
helpers.ClosePrompt(err)

task := core.Tasks[i]
actionPrompt := promptui.Select{
HideHelp: true,
Label: "[choose]: action to run",
Items: task.Actions,
Templates: core.ActionTpl,
Size: 10,
Stdout: &helpers.BellSkipper{},
}
j, _, err := actionPrompt.Run()
helpers.ClosePrompt(err)

action := task.Actions[j]
runConfirmPrompt(mode, task, action)
} else {
runAuto(mode)
helpers.ClosePrompt(err)
}
i, _, err := taskPrompt.Run()
helpers.ClosePrompt(err)

task := core.Tasks[i]
actionPrompt := promptui.Select{
HideHelp: true,
Label: "[choose]: action to run",
Items: task.Actions,
Templates: core.ActionTpl,
Size: 10,
Stdout: &helpers.BellSkipper{},
}
j, _, err := actionPrompt.Run()
helpers.ClosePrompt(err)

action := task.Actions[j]
runConfirmPrompt(mode, task, action)
}

func auth() {
Expand Down
8 changes: 5 additions & 3 deletions config/cfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ export _apt_packages_=(
"apt-transport-https"
"build-essential"
"ca-certificates"
"curl"
"file"
"git"
"procps"
"software-properties-common"
"zsh"
)

export _brew_packages_=(
"curl"
"gcc"
"git"
"htop"
"make"
"tree"
"xclip"
"zsh"
)

export _brew_k8s_packages_=(
Expand Down
2 changes: 1 addition & 1 deletion exec/dotfiles/rc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ -f "$HOME"/.zshrc ]; then
ui_info "$HOME/.zshrc detected"
if ! grep -q "$sourcing" < "$HOME"/.zshrc ; then
ui_info "dotfile sourcing not found"
ui_cmd "printf 'source $HOME/.aliases; source $HOME/.functions' >> $HOME/.zshrc"
ui_cmd "$sourcing >> $HOME/.zshrc"
printf "\n%s\n" "$sourcing" >> "$HOME"/.zshrc
else
ui_info "sourcing already found, terminating"
Expand Down
4 changes: 3 additions & 1 deletion exec/packages/apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ ui_cmd "${exec_b[@]}" ; "${exec_b[@]}"

for i in "${_apt_packages_[@]}"
do
exec=(sudo apt install $i -y)
exec=(sudo apt install "$i" -y)

ui_info "installing $i package"
ui_cmd "${exec[@]}" ; "${exec[@]}"
done



ui_done
31 changes: 23 additions & 8 deletions exec/packages/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
source "$PWD"/config/ui.sh
source "$PWD"/config/cfg.sh

exec_a=(/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
exec_b=(brew update)
exec_c=(brew upgrade)
exec_d=(brew cleanup)
Expand All @@ -14,23 +13,39 @@ ui_start

if [ "$(which brew)" != 0 ]; then
ui_info "installing brew executable"
ui_cmd "${exec_a[@]}" ; "${exec_a[@]}"
ui_cmd "NONINTERACTIVE=1 /bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ -f "$HOME"/.zshrc ]; then
ui_info "$HOME/.zshrc detected"
if ! grep -q "eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" < "$HOME"/.zshrc ; then
ui_info "dotfile sourcing not found"
ui_cmd "eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) >> $HOME/.zshrc"
printf "\n%s\neval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" >> "$HOME"/.zshrc
else
ui_info "sourcing already found, terminating"
fi
else
ui_error "$HOME/.zshrc not found"
fi
else
ui_info "\"brew\" command already exist. Exiting.."
fi



ui_cmd "eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
ui_cmd "${exec_b[@]}" ; "${exec_b[@]}"
ui_cmd "${exec_c[@]}" ; "${exec_c[@]}"
ui_cmd "${exec_d[@]}" ; "${exec_d[@]}"
ui_cmd "${exec_e[@]}" ; "${exec_e[@]}"

for i in "${_brew_packages_[@]}"
do
exec=(brew install $i -y)
exec=(brew install "$i")

ui_info "installing $i package"
ui_cmd "${exec[@]}" ; "${exec[@]}"
done

ui_cmd "${exec_b[@]}" ; "${exec_b[@]}"
ui_cmd "${exec_c[@]}" ; "${exec_c[@]}"
ui_cmd "${exec_d[@]}" ; "${exec_d[@]}"
ui_cmd "${exec_e[@]}" ; "${exec_e[@]}"

ui_done
3 changes: 1 addition & 2 deletions internal/core/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ var Modes = []Mode{
{
Name: "step-by-step",
Description: "Setup by category",

},{
}, {
Name: "!automatic",
Description: "Setup with all steps included automatically",
}}
3 changes: 1 addition & 2 deletions internal/core/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
import "github.com/manifoldco/promptui"

var ModeTpl = &promptui.SelectTemplates{
Label: `⚙️ | {{ . | red | bold | underline }}`,
Label: `⚙️ | {{ . | red | bold | underline }}`,
Selected: "🔴 {{ .Name | bgRed | black | bold }}",
Active: "🔴 {{ .Name | bgRed | black }}",
Inactive: " {{ .Name | white }}",
Expand All @@ -12,7 +12,6 @@ var ModeTpl = &promptui.SelectTemplates{
{{ "Goal" | underline }}: {{ .Description | italic | faint }}`,
}


var TaskTpl = &promptui.SelectTemplates{
Help: "{{ \"Toggle search: / key\" | faint }}",
Label: `🛠️ | {{ . | yellow | bold | underline }}`,
Expand Down
Binary file added main
Binary file not shown.

0 comments on commit 138c225

Please sign in to comment.