Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect available flags for extensions #2557

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Input struct {
networkName string
useNewActionCache bool
localRepository []string
listOptions bool
}

func (i *Input) resolve(path string) string {
Expand Down
4 changes: 4 additions & 0 deletions cmd/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
}

func displayNotices(input *Input) {
// Avoid causing trouble parsing the json
if input.listOptions {
return
}

Check warning on line 26 in cmd/notices.go

View check run for this annotation

Codecov / codecov/patch

cmd/notices.go#L23-L26

Added lines #L23 - L26 were not covered by tests
select {
case notices := <-noticesLoaded:
if len(notices) > 0 {
Expand Down
24 changes: 24 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand All @@ -21,6 +22,7 @@
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/pflag"
"gopkg.in/yaml.v3"

"github.com/nektos/act/pkg/artifactcache"
Expand All @@ -31,6 +33,13 @@
"github.com/nektos/act/pkg/runner"
)

type Flag struct {
Name string `json:"name"`
Default string `json:"default"`
Type string `json:"type"`
Description string `json:"description"`
}

// Execute is the entry point to running the CLI
func Execute(ctx context.Context, version string) {
input := new(Input)
Expand All @@ -44,6 +53,7 @@
Version: version,
SilenceUsage: true,
}

Check warning on line 56 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L56

Added line #L56 was not covered by tests
rootCmd.Flags().BoolP("watch", "w", false, "watch the contents of the local repo and run when files change")
rootCmd.Flags().BoolP("list", "l", false, "list workflows")
rootCmd.Flags().BoolP("graph", "g", false, "draw workflows")
Expand Down Expand Up @@ -104,6 +114,7 @@
rootCmd.PersistentFlags().StringVarP(&input.networkName, "network", "", "host", "Sets a docker network name. Defaults to host.")
rootCmd.PersistentFlags().BoolVarP(&input.useNewActionCache, "use-new-action-cache", "", false, "Enable using the new Action Cache for storing Actions locally")
rootCmd.PersistentFlags().StringArrayVarP(&input.localRepository, "local-repository", "", []string{}, "Replaces the specified repository and ref with a local folder (e.g. https://github.com/test/test@v0=/home/act/test or test/test@v0=/home/act/test, the latter matches any hosts or protocols)")
rootCmd.PersistentFlags().BoolVar(&input.listOptions, "list-options", false, "Print a json structure of compatible options")

Check warning on line 117 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L117

Added line #L117 was not covered by tests
rootCmd.SetArgs(args())

if err := rootCmd.Execute(); err != nil {
Expand Down Expand Up @@ -242,6 +253,16 @@
return nil
}

func listOptions(cmd *cobra.Command) error {
flags := []Flag{}
cmd.LocalFlags().VisitAll(func(f *pflag.Flag) {
flags = append(flags, Flag{Name: f.Name, Default: f.DefValue, Description: f.Usage, Type: f.Value.Type()})
})
a, err := json.Marshal(flags)
fmt.Println(string(a))
return err

Check warning on line 263 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L256-L263

Added lines #L256 - L263 were not covered by tests
}

func readArgsFile(file string, split bool) []string {
args := make([]string, 0)
f, err := os.Open(file)
Expand Down Expand Up @@ -359,6 +380,9 @@
if ok, _ := cmd.Flags().GetBool("man-page"); ok {
return generateManPage(cmd)
}
if input.listOptions {
return listOptions(cmd)
}

Check warning on line 385 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L383-L385

Added lines #L383 - L385 were not covered by tests

if ret, err := container.GetSocketAndHost(input.containerDaemonSocket); err != nil {
log.Warnf("Couldn't get a valid docker connection: %+v", err)
Expand Down
Loading