Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejlv committed Jan 11, 2025
1 parent 125ed23 commit e39a10c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func main() {
// fmt.Printf("Command '%s' not found in config\n", cmdToRun)
utils.Logger(utils.LoggerOptions{
Level: "error",
Message: "Command was not found",
Message: fmt.Sprintf("Command '%s' not found in config", cmdToRun),
})
}
8 changes: 7 additions & 1 deletion utils/init.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package utils

import (
"fmt"
)

func Init() {
Logger(LoggerOptions{Level: "info", Message: "Command is not implemented yet"})

commandName := Prompt("What is the name of the command? ")
fmt.Println(commandName)
}
2 changes: 1 addition & 1 deletion utils/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var ConfigFileName string = ".actions"
var CurrentVersion string = "0.1.17"
var CurrentVersion string = "0.1.18"

type CommandsArray struct {
Name string
Expand Down
10 changes: 5 additions & 5 deletions utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ type LoggerOptions struct {
}

var (
error = color.New(color.FgRed, color.Bold)
success = color.New(color.FgGreen, color.Bold)
info = color.New(color.FgBlue, color.Bold)
warn = color.New(color.FgYellow, color.Bold)
error = color.New(color.FgRed)
success = color.New(color.FgGreen)
info = color.New(color.FgBlue)
warn = color.New(color.FgYellow)
)

func Logger(options LoggerOptions) {
switch options.Level {
case "error":
error.Println("[ERROR]", options.Message)
case "success":
success.Println(options.Message)
success.Println("[SUCCESS]", options.Message)
case "info":
info.Println("[INFO]", options.Message)
case "warn":
Expand Down
15 changes: 15 additions & 0 deletions utils/prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package utils

import (
"bufio"
"fmt"
"os"
"strings"
)

func Prompt(question string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(question)
answer, _ := reader.ReadString('\n')
return strings.TrimSpace(answer)
}
4 changes: 0 additions & 4 deletions utils/runCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import (
"os"
"os/exec"
"runtime"

"github.com/fatih/color"
)

var errorColor = color.New(color.FgRed, color.Bold)

func RunCmd(cmdString string) {
var cmd *exec.Cmd

Expand Down
28 changes: 9 additions & 19 deletions utils/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,23 @@ var (

const usageTemplate = `
Usage:
%s <command> Execute a specific command from .actions
%s --all Run all available commands from .actions
%s --list List all available commands from .actions
%s --version Print the current version
%s --upgrade Upgrade to the latest version
%s --init Create a .actions file
action <command> Execute a specific command from .actions
action --all Run all available commands from .actions
action --list List all available commands from .actions
action --version Print the current version
action --upgrade Upgrade to the latest version
action --init Create a .actions file
Examples:
%s build Run the build command - Loads the build command from .actions
%s test Run the test command - Loads the test command from .actions
action build Run the build command - Loads the build command from .actions
action test Run the test command - Loads the test command from .actions
For more information, visit: https://github.com/lassejlv/actionfile
`

func Usage() {
// Format usage with colors
usage := fmt.Sprintf(usageTemplate,
commandColor.Sprint(cliName),
commandColor.Sprint(cliName),
exampleColor.Sprint(cliName),
exampleColor.Sprint(cliName),
exampleColor.Sprint(cliName),
exampleColor.Sprint(cliName),
exampleColor.Sprint(cliName),
commandColor.Sprint(cliName),
)

headerColor.Println("\nActionfile Command Runner")
fmt.Println(usage)
fmt.Printf(usageTemplate)
}

0 comments on commit e39a10c

Please sign in to comment.