Skip to content

Commit

Permalink
Main.
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviof committed Sep 22, 2019
1 parent b46723d commit 037d552
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"flag"
"fmt"
"os"
)

// fatal print out error as a shell comment and exit on error.
func fatal(err error) {
fmt.Fprintf(os.Stderr, fmt.Sprintf("# [ERROR] %v\n", err))
os.Exit(1)
}

// commandLineParser handle command line flags, display help message.
func commandLineParser(config *Config) {
flag.Usage = func() {
fmt.Printf(`## path-helper
Helper command-line application to compose "PATH" expression based in a "paths.d"
directory, respecting order of files and adding toggles to skip entries.
To export new "PATH" to your shell instance, run "eval" against "path-helper"
output. Examples below.
Usage:
$ path-helper [-h|--help|flags]
Examples:
$ path-helper -v
$ path-helper -v -s=false -d=false
Shell-Export:
$ eval "$(path-helper -s=false -d=false)"
$ echo $PATH
Command-Line Options:
`)
flag.PrintDefaults()
}

flag.StringVar(&config.BaseDir, "b", "/etc/paths.d", "Base directory")
flag.BoolVar(&config.SkipNotFound, "d", true, "Skip not found directories")
flag.BoolVar(&config.SkipDuplicates, "s", true, "Skip duplicated entries")
flag.BoolVar(&config.Verbose, "v", false, "Verbose")

flag.Parse()
}

func main() {
config := &Config{}
commandLineParser(config)

p := NewPathHelper(config)
expr, err := p.RenderExpression()
if err != nil {
fatal(err)
}
fmt.Println(expr)
}

0 comments on commit 037d552

Please sign in to comment.