1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

fix #89 - support .actrc file

This commit is contained in:
Casey Lee 2020-02-24 22:11:33 -08:00
parent fbecf70cc2
commit f28cd9e692

View file

@ -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 {