Skip to content

Commit

Permalink
print always newline on exit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dim0x69 committed Oct 22, 2024
1 parent 3f96e46 commit c9b7bd0
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func setLogLevel() {
}

func errorExit(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format, args...)
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func main() {

// Check for subcommands
if flag.NArg() < 1 {
errorExit("Usage: mdx [-file <markdown-file>] <command> [args]\n")
errorExit("Usage: mdx [-file <markdown-file>] <command> [args]")
}

commandName := flag.Arg(0)
Expand All @@ -94,21 +94,15 @@ func main() {

loadLaunchers()

// Function to load commands from a list of markdown files
loadCommandsFromFiles := func(mdFiles []string) {
for _, mdFile := range mdFiles {
logrus.Debug(fmt.Sprintf("Loading file %s", mdFile))
err := loadCommands(mdFile)
if err != nil {
errorExit("Error loading commands from %s: %v", mdFile, err)
}
mdFiles := getMarkdownFilePaths(*fileFlag)
for _, mdFile := range mdFiles {
logrus.Debug(fmt.Sprintf("Loading file %s", mdFile))
err := loadCommands(mdFile)
if err != nil {
errorExit("Error loading commands from %s: %v", mdFile, err)
}
}

mdFiles := getMarkdownFilePaths(*fileFlag)
loadCommandsFromFiles(mdFiles)

// Execute command
if command, ok := commands[commandName]; ok {
err := executeCommandBlock(&command, commandArgs...)
if err != nil {
Expand Down

0 comments on commit c9b7bd0

Please sign in to comment.