From 76a8bfc4fc2afef66a1296d67eafd0f33a57d007 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Mon, 24 Feb 2020 22:11:33 -0800 Subject: [PATCH] fix #89 - support .actrc file --- .actrc | 1 + Makefile | 2 +- cmd/root.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .actrc diff --git a/.actrc b/.actrc new file mode 100644 index 00000000..9e89b8b9 --- /dev/null +++ b/.actrc @@ -0,0 +1 @@ +-P ubuntu-latest=nektos/act-environments-ubuntu:18.04 diff --git a/Makefile b/Makefile index abd9ec83..a112b546 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ build: go build -ldflags "-X main.version=$(VERSION)" -o dist/local/act main.go test: - $(ACT) -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 + $(ACT) install: build @cp dist/local/act /usr/local/bin/act diff --git a/cmd/root.go b/cmd/root.go index efbc05c0..6732993d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,9 +1,12 @@ package cmd import ( + "bufio" "context" + "fmt" "os" "path/filepath" + "strings" "github.com/nektos/act/pkg/common" @@ -41,12 +44,43 @@ func Execute(ctx context.Context, version string) { rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps") rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode") + rootCmd.SetArgs(args()) if err := rootCmd.Execute(); err != nil { os.Exit(1) } } +func args() []string { + args := make([]string, 0) + for _, dir := range []string{ + os.Getenv("HOME"), + ".", + } { + args = append(args, readArgsFile(fmt.Sprintf("%s/.actrc", dir))...) + } + args = append(args, os.Args[1:]...) + return args +} + +func readArgsFile(file string) []string { + args := make([]string, 0) + f, err := os.Open(file) + if err != nil { + return args + } + defer f.Close() + scanner := bufio.NewScanner(f) + for scanner.Scan() { + arg := scanner.Text() + if strings.HasPrefix(arg, "-") { + args = append(args, strings.Fields(arg)...) + } + } + return args + +} + func setupLogging(cmd *cobra.Command, args []string) { verbose, _ := cmd.Flags().GetBool("verbose") if verbose {