-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add run command use to oneshot execute a shigoto (#13)
- Loading branch information
1 parent
444667b
commit b88a252
Showing
5 changed files
with
98 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
version: '3' | ||
|
||
vars: | ||
VERSION: 0.2.5 | ||
VERSION: 0.3.0 | ||
REVISION: { sh: git rev-parse HEAD } | ||
|
||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package run | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"slices" | ||
|
||
"github.com/mdouchement/logger" | ||
"github.com/mdouchement/shigoto/pkg/runner" | ||
"github.com/mdouchement/shigoto/pkg/shigoto" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Command launches the validate subcommand. | ||
var Command = &cobra.Command{ | ||
Use: "run file.yml ALL|baito [baito]...", | ||
Short: "Run (oneshot) the given shigoto file", | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
logrus := logrus.New() | ||
logrus.SetFormatter(&logger.LogrusTextFormatter{ | ||
ForceColors: true, | ||
ForceFormatting: true, | ||
PrefixRE: regexp.MustCompile(`^(\[.*?\])\s`), | ||
FullTimestamp: true, | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
}) | ||
log := logger.WrapLogrus(logrus) | ||
|
||
// | ||
|
||
shigoto, err := shigoto.Load(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var selected []runner.Runner | ||
for _, baito := range shigoto.Baito { | ||
fmt.Println("Found baito:", baito.Name()) | ||
|
||
if len(args) <= 1 { | ||
continue | ||
} | ||
|
||
if args[1] == "ALL" { | ||
selected = append(selected, baito.Commands()...) | ||
continue | ||
} | ||
|
||
if slices.Contains[[]string, string](args[1:], baito.Name()) { | ||
selected = append(selected, baito.Commands()...) | ||
} | ||
} | ||
fmt.Println("---") | ||
|
||
chain := runner.Chain(selected...) | ||
chain.AttachLogger(log) | ||
chain.Run() | ||
return chain.Error() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters