Skip to content

Commit e451bff

Browse files
committed
feat: small refactor and fix lint issues
1 parent 1e5dfb2 commit e451bff

39 files changed

Lines changed: 533 additions & 349 deletions

.github/copilot-instructions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ and `"github.com/stretchr/testify/require"` packages.
4141
- Unit tests should reside in a file named as per the file containing the code being tested, with the suffix `_test.go`.
4242
- Integration tests should reside in a file named as per the file or package containing the code being tested, with the suffix `_integration_test.go`.
4343
- This package uses concurrency so tests should be run with the `-race` flag to ensure they are thread-safe. This should be done after verifying unit tests pass in isolation.
44+
45+
### Building and Running
46+
47+
- The binary is built from the `./cmd` package.
48+
- Use `make build` to build the project.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
porch
22
porch.exe
3+
!/cmd/porch
34

45
.vscode
56

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
default:
2-
@echo "No default target specified. Please specify a target."
1+
.PHONY: build
2+
build:
3+
@echo "Building the project..."
4+
@go build -o porch ./cmd/porch
35

6+
.PHONY: testcover
47
testcover:
58
@echo "Running tests with coverage..."
69
@go test -coverprofile=coverage.out ./...
710
@go tool cover -html=coverage.out -o coverage.html
811
@echo "Coverage report generated: coverage.html"
912

13+
.PHONY: test
1014
test:
1115
@echo "Running tests..."
16+
@go test ./...
17+
18+
.PHONY: testrace
19+
testrace:
20+
@echo "Running tests with race detection..."
1221
@go test -race ./...
1322

23+
.PHONY: lint
1424
lint:
1525
@echo "Running linter..."
1626
@golangci-lint run --fix

cmd/cmd.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

cmd/cmdstate/ctxkey.go

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/urfave/cli/v3"
1515
)
1616

17+
// ConfigCmd is the command for getting configuration information and examples.
1718
var ConfigCmd = &cli.Command{
1819
Name: "config",
1920
Usage: "Get info on configuration format and commands",
@@ -72,10 +73,10 @@ func actionFunc(ctx context.Context, cmd *cli.Command) error {
7273
fmt.Printf("%s\n\nSchema:\n\n", sp.GetCommandDescription())
7374

7475
if cmd.Bool("markdown") {
75-
sw.WriteMarkdownDoc(os.Stdout)
76+
sw.WriteMarkdownDoc(os.Stdout) //nolint:errcheck
7677
}
7778

78-
sw.WriteYAMLExample(os.Stdout)
79+
sw.WriteYAMLExample(os.Stdout) //nolint:errcheck
7980

8081
return nil
8182
}
@@ -86,14 +87,14 @@ var schemaCmd = &cli.Command{
8687
Action: schemaCmdActionFunc,
8788
}
8889

89-
func schemaCmdActionFunc(ctx context.Context, cmd *cli.Command) error {
90+
func schemaCmdActionFunc(ctx context.Context, _ *cli.Command) error {
9091
factory, ok := ctx.Value(commands.FactoryContextKey{}).(commands.CommanderFactory)
9192
if !ok {
9293
return cli.Exit("failed to get command factory from context", 1)
9394
}
9495

9596
sw := schema.NewBaseSchemaGenerator()
96-
sw.WriteJSONSchema(os.Stdout, factory)
97+
sw.WriteJSONSchema(os.Stdout, factory) //nolint:errcheck
9798

9899
return nil
99100
}
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Copyright (c) matt-FFFFFF 2025. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
// Package main is the entry point for the porch command-line application.
4+
// Package main contains the porch command-line interface (CLI).
55
package main
66

77
import (
88
"context"
99
"os"
1010

11-
"github.com/matt-FFFFFF/porch/cmd"
11+
"github.com/matt-FFFFFF/porch"
12+
"github.com/matt-FFFFFF/porch/cmd/porch/config"
13+
"github.com/matt-FFFFFF/porch/cmd/porch/run"
14+
"github.com/matt-FFFFFF/porch/cmd/porch/show"
1215
"github.com/matt-FFFFFF/porch/internal/commandregistry"
1316
"github.com/matt-FFFFFF/porch/internal/commands"
1417
"github.com/matt-FFFFFF/porch/internal/commands/copycwdtotemp"
@@ -21,10 +24,27 @@ import (
2124
"github.com/urfave/cli/v3"
2225
)
2326

24-
var (
25-
version = "dev"
26-
commit = "unknown"
27-
)
27+
// rootCmd is the root command for the CLI.
28+
var rootCmd = &cli.Command{
29+
Commands: []*cli.Command{
30+
config.ConfigCmd,
31+
run.RunCmd,
32+
show.ShowCmd,
33+
},
34+
Writer: os.Stdout,
35+
ErrWriter: os.Stderr,
36+
Name: "porch",
37+
Description: `Porch is a sophisticated Go-based process orchestration framework
38+
designed for running and managing complex command workflows. It provides a flexible,
39+
YAML-driven approach to define, compose, and execute command chains with advanced
40+
flow control, parallel processing, and comprehensive error handling.`,
41+
Usage: "porch run myfile.yaml",
42+
Copyright: "Copyright (c) matt-FFFFFF 2025. All rights reserved.",
43+
Authors: []any{
44+
"Matt White (matt-FFFFFF)",
45+
},
46+
EnableShellCompletion: true,
47+
}
2848

2949
func main() {
3050
ctx, cancel := context.WithCancel(context.Background())
@@ -35,12 +55,7 @@ func main() {
3555

3656
go signalbroker.Watch(ctx, sigCh, cancel)
3757

38-
cmd.RootCmd.Version = version
39-
cmd.RootCmd.ExtraInfo = func() map[string]string {
40-
return map[string]string{
41-
"commit": commit,
42-
}
43-
}
58+
rootCmd.Version = porch.Version
4459

4560
factory := commandregistry.New(
4661
serialcommand.Register,
@@ -50,12 +65,9 @@ func main() {
5065
shellcommand.Register,
5166
)
5267

53-
cmd.RootCmd.Before = cli.BeforeFunc(func(c context.Context, cmd *cli.Command) (context.Context, error) {
54-
ctx = context.WithValue(ctx, commands.FactoryContextKey{}, factory)
55-
return ctx, nil
56-
})
68+
ctx = context.WithValue(ctx, commands.FactoryContextKey{}, factory)
5769

58-
_ = cmd.RootCmd.Run(ctx, os.Args) // Err is handled by cli framework
70+
_ = rootCmd.Run(ctx, os.Args) // Err is handled by cli framework
5971

6072
ctxlog.Logger(ctx).Info("command completed successfully")
6173
}
File renamed without changes.

cmd/run/run.go renamed to cmd/porch/run/run.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"os"
1010

11-
"github.com/matt-FFFFFF/porch/cmd/cmdstate"
11+
"github.com/matt-FFFFFF/porch/internal/commands"
1212
"github.com/matt-FFFFFF/porch/internal/config"
1313
"github.com/matt-FFFFFF/porch/internal/runbatch"
1414
"github.com/urfave/cli/v3"
@@ -35,7 +35,8 @@ var RunCmd = &cli.Command{
3535
Name: "run",
3636
Description: `Run a command or batch of commands defined in a YAML file.
3737
This command executes the commands defined in the specified YAML file and outputs the results.
38-
The YAML file should be structured according to the Porch configuration format, which allows for defining commands, their parameters, and execution flow.
38+
The YAML file should be structured according to the Porch configuration format,
39+
which allows for defining commands, their parameters, and execution flow.
3940
4041
To save the results to a file, specify the output file name as an argument.
4142
`,
@@ -90,7 +91,9 @@ func actionFunc(ctx context.Context, cmd *cli.Command) error {
9091
return cli.Exit(fmt.Sprintf("failed to read file %s: %s", yamlFileName, err.Error()), 1)
9192
}
9293

93-
rb, err := config.BuildFromYAML(ctx, cmdstate.Factory, bytes)
94+
factory := ctx.Value(commands.FactoryContextKey{}).(commands.CommanderFactory)
95+
96+
rb, err := config.BuildFromYAML(ctx, factory, bytes)
9497
if err != nil {
9598
return cli.Exit(fmt.Sprintf("failed to build config from file %s: %s", yamlFileName, err.Error()), 1)
9699
}

0 commit comments

Comments
 (0)