Skip to content

Commit

Permalink
Add option to specify the config file path
Browse files Browse the repository at this point in the history
  • Loading branch information
marema31 committed Feb 22, 2019
1 parent 0c953b2 commit ed3d503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion logwriter/logwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logwriter

import (
"bytes"
"fmt"
"os"

"github.com/marema31/jocasta/config"
Expand Down Expand Up @@ -31,7 +32,7 @@ func New(stream string, c *config.Config) (*LogWriter, error) {
currentsize: 0,
file: f,
}

fmt.Printf("Will log std%s on %s with limit:%d and backups:%d\n", stream, p.File, p.Maxsize, p.Backups)
return l, nil
}

Expand Down
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,39 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"

"github.com/marema31/jocasta/config"
"github.com/marema31/jocasta/logwriter"
)

func main() {
if len(os.Args) < 2 || os.Args[1] == "-h" {
fmt.Println("usage: jocasta command to run with args")

i := 1
configPath := "."
configFile := ".jocasta"

if len(os.Args) > 2 && os.Args[1] == "-c" {
i = 3
configPath = filepath.Dir(os.Args[2])
configFile = filepath.Base(os.Args[2])
}

if (len(os.Args)-i) < 1 || os.Args[i] == "-h" {
fmt.Println("usage: jocasta [-c configFileWithoutExtension] command to run with args")
fmt.Println()
fmt.Println("The config file name must be provided without the file extension, jocasta will try json, toml and yaml")
os.Exit(0)
}

config, err := config.New(".", "jocasta", os.Args[1])
config, err := config.New(configPath, configFile, os.Args[i])
if err != nil {
log.Fatal(err)
}

fmt.Printf("Will run %s\n", strings.Join(os.Args[i:], " "))
cmd := exec.Command(os.Args[1], os.Args[2:]...)

stderr, err := cmd.StderrPipe()
Expand Down Expand Up @@ -65,6 +81,7 @@ func main() {
}
}

// will be called as goroutine to allow the stdout and stderr to be captured in parallel
func transfer(in io.ReadCloser, out io.Writer, wg *sync.WaitGroup) {
if _, err := io.Copy(out, in); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit ed3d503

Please sign in to comment.