Skip to content

Commit 8fe77fb

Browse files
authored
Merge pull request #15 from ReconfigureIO/fix/sim-log-panic
break genLogSubcommand down for each command
2 parents 06f8038 + 488784f commit 8fe77fb

File tree

5 files changed

+192
-118
lines changed

5 files changed

+192
-118
lines changed

cmd/build.go

+64-19
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,86 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
7+
"reflect"
68

79
"github.com/ReconfigureIO/cobra"
810
"github.com/ReconfigureIO/reco"
911
"github.com/ReconfigureIO/reco/logger"
1012
)
1113

12-
var buildVars = struct {
13-
wait bool
14-
force bool
15-
}{
16-
wait: true,
17-
}
14+
var (
15+
buildVars = struct {
16+
wait bool
17+
force bool
18+
}{
19+
wait: true,
20+
}
1821

19-
// buildCmd represents the upload command
20-
var buildCmdStart = &cobra.Command{
21-
Use: "run",
22-
Aliases: []string{"r", "start", "starts", "create"},
23-
Short: "Start a new build",
24-
Long: `Start a new build.
25-
A successful build creates an image that can be deployed to an F1 instance. Your FPGA code will be compiled, optimized and assigned a unique ID.
26-
Each subdirectory within "cmd" containing a main.go file will become a runnable command available for use when you deploy your build - reco deploy run <build_ID> <my_cmd>.
27-
`,
28-
Run: startBuild,
29-
}
22+
// buildCmd represents the upload command
23+
buildCmdStart = &cobra.Command{
24+
Use: "run",
25+
Aliases: []string{"r", "start", "starts", "create"},
26+
Short: "Start a new build",
27+
Long: `Start a new build.
28+
A successful build creates an image that can be deployed to an F1 instance. Your FPGA code will be compiled, optimized and assigned a unique ID.
29+
Each subdirectory within "cmd" containing a main.go file will become a runnable command available for use when you deploy your build - reco deploy run <build_ID> <my_cmd>.
30+
`,
31+
Run: startBuild,
32+
}
33+
34+
buildCmdLog = &cobra.Command{
35+
Use: fmt.Sprintf("log [build_ID]"),
36+
Aliases: []string{"logs"},
37+
Short: fmt.Sprintf("Stream logs for a build"),
38+
Long: fmt.Sprintf("Stream logs for a build previously started with 'reco build run'."),
39+
PreRun: buildLogPreRun,
40+
Run: func(cmd *cobra.Command, args []string) {
41+
l := reflect.ValueOf(tool).MethodByName("Build").Call(nil)[0].Interface()
42+
if err := l.(reco.Job).Log(args[0], os.Stdout); err != nil {
43+
exitWithError(err)
44+
}
45+
},
46+
}
47+
48+
buildLogPreRun = func(cmd *cobra.Command, args []string) {
49+
if len(args) == 0 {
50+
exitWithError("ID required")
51+
}
52+
}
53+
54+
buildCmdStop = &cobra.Command{
55+
Use: "stop [build_ID]",
56+
Aliases: []string{"s", "stp", "stops"},
57+
Short: fmt.Sprintf("Stop a build"),
58+
Long: fmt.Sprintf("Stop a build previously started with 'reco build run'"),
59+
PreRun: buildStopPreRun,
60+
Run: func(cmd *cobra.Command, args []string) {
61+
l := reflect.ValueOf(tool).MethodByName("Build").Call(nil)[0].Interface()
62+
if err := l.(reco.Job).Stop(args[0]); err != nil {
63+
exitWithError(err)
64+
}
65+
logger.Std.Printf("build stopped successfully")
66+
},
67+
}
68+
69+
buildStopPreRun = func(cmd *cobra.Command, args []string) {
70+
if len(args) == 0 {
71+
exitWithError("ID required")
72+
}
73+
}
74+
)
3075

3176
func init() {
3277
buildCmdStart.PersistentFlags().BoolVarP(&buildVars.wait, "wait", "w", buildVars.wait, "Wait for the build to complete. If wait=false, logs will only be displayed up to where the build is started and assigned its unique ID. Use 'reco build list' to check the status of your builds")
3378
buildCmdStart.PersistentFlags().BoolVarP(&buildVars.force, "force", "f", buildVars.force, "Force a build to start. Ignore source code validation")
3479

3580
buildCmd := genDevCommand("build", "build", "b", "builds")
3681
buildCmd.AddCommand(genListSubcommand("builds", "Build"))
37-
buildCmd.AddCommand(genLogSubcommand("build", "build"))
38-
buildCmd.AddCommand(genStopSubcommand("build", "Build"))
82+
buildCmd.AddCommand(buildCmdLog)
83+
buildCmd.AddCommand(buildCmdStop)
3984
buildCmd.AddCommand(buildCmdStart)
4085
buildCmd.PersistentFlags().StringVar(&project, "project", project, "Project to use. If unset, the active project is used")
4186

cmd/deployment.go

+69-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
package cmd
22

33
import (
4+
"fmt"
5+
"os"
6+
"reflect"
7+
48
"github.com/ReconfigureIO/cobra"
59
"github.com/ReconfigureIO/reco"
610
"github.com/ReconfigureIO/reco/logger"
711
)
812

9-
var deploymentVars = struct {
10-
wait string
11-
}{
12-
wait: "true",
13-
}
13+
var (
14+
deploymentVars = struct {
15+
wait string
16+
}{
17+
wait: "true",
18+
}
1419

15-
var deploymentCmdStart = &cobra.Command{
16-
Use: "run [flags] <build_ID> <your_cmd> -- [args]",
17-
Aliases: []string{"r", "start", "starts"},
18-
Short: "Deploy a build image and command to an F1 instance",
19-
Long: `Deploy a build image and run a command from that build on an F1 instance.
20+
deploymentCmdStart = &cobra.Command{
21+
Use: "run [flags] <build_ID> <your_cmd> -- [args]",
22+
Aliases: []string{"r", "start", "starts"},
23+
Short: "Deploy a build image and command to an F1 instance",
24+
Long: `Deploy a build image and run a command from that build on an F1 instance.
2025
2126
More about commands:
2227
@@ -38,25 +43,67 @@ of your arguments may conflict with this command. If this is the case,
3843
use "--" to specify that all further arguments should be provided to
3944
your command. The two forms are equivalent:
4045
"reco run my-image my-cmd -- 1" and "reco run my-image my-cmd 1"
41-
`,
42-
Run: startDeployment,
43-
}
46+
`,
47+
Run: startDeployment,
48+
}
4449

45-
var deploymentCmdConnect = &cobra.Command{
46-
Use: "connect <deploy_ID>",
47-
Aliases: []string{"c", "connects"},
48-
Short: "Connect to a running deployment",
49-
Long: "Connect to a running deployment.",
50-
Run: connectDeployment,
51-
}
50+
deploymentCmdConnect = &cobra.Command{
51+
Use: "connect <deploy_ID>",
52+
Aliases: []string{"c", "connects"},
53+
Short: "Connect to a running deployment",
54+
Long: "Connect to a running deployment.",
55+
Run: connectDeployment,
56+
}
57+
58+
deploymentCmdLog = &cobra.Command{
59+
Use: fmt.Sprintf("log [deployment_ID]"),
60+
Aliases: []string{"logs"},
61+
Short: fmt.Sprintf("Stream logs for a deployment"),
62+
Long: fmt.Sprintf("Stream logs for a deployment previously started with 'reco deploy run'."),
63+
PreRun: deploymentLogPreRun,
64+
Run: func(cmd *cobra.Command, args []string) {
65+
l := reflect.ValueOf(tool).MethodByName("Deployment").Call(nil)[0].Interface()
66+
if err := l.(reco.Job).Log(args[0], os.Stdout); err != nil {
67+
exitWithError(err)
68+
}
69+
},
70+
}
71+
72+
deploymentLogPreRun = func(cmd *cobra.Command, args []string) {
73+
if len(args) == 0 {
74+
exitWithError("ID required")
75+
}
76+
}
77+
78+
deploymentCmdStop = &cobra.Command{
79+
Use: "stop [deployment_ID]",
80+
Aliases: []string{"s", "stp", "stops"},
81+
Short: fmt.Sprintf("Stop a deployment"),
82+
Long: fmt.Sprintf("Stop a deployment previously started with 'reco deploy run'"),
83+
PreRun: deploymentStopPreRun,
84+
Run: func(cmd *cobra.Command, args []string) {
85+
l := reflect.ValueOf(tool).MethodByName("Deployment").Call(nil)[0].Interface()
86+
if err := l.(reco.Job).Stop(args[0]); err != nil {
87+
exitWithError(err)
88+
}
89+
logger.Std.Printf("deployment stopped successfully")
90+
},
91+
}
92+
93+
deploymentStopPreRun = func(cmd *cobra.Command, args []string) {
94+
if len(args) == 0 {
95+
exitWithError("ID required")
96+
}
97+
}
98+
)
5299

53100
func init() {
54101
deploymentCmdStart.PersistentFlags().StringVarP(&deploymentVars.wait, "wait", "w", deploymentVars.wait, "Wait for the run to complete. If false, it only starts the command without waiting for it to complete")
55102

56103
deploymentCmd := genDevCommand("deploy", "deployment", "d", "dep", "deps", "deployments", "deployment")
57104
deploymentCmd.AddCommand(genListSubcommand("deployments", "Deployment"))
58-
deploymentCmd.AddCommand(genLogSubcommand("deploy", "deployment"))
59-
deploymentCmd.AddCommand(genStopSubcommand("deployment", "Deployment"))
105+
deploymentCmd.AddCommand(deploymentCmdLog)
106+
deploymentCmd.AddCommand(deploymentCmdStop)
60107
deploymentCmd.AddCommand(deploymentCmdStart)
61108
deploymentCmd.AddCommand(deploymentCmdConnect)
62109
deploymentCmd.PersistentFlags().StringVar(&project, "project", project, "Project to use. If unset, the active project is used")

cmd/log.go

-32
This file was deleted.

cmd/stop.go

-33
This file was deleted.

cmd/test.go

+59-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
11
package cmd
22

33
import (
4+
"fmt"
5+
"os"
6+
"reflect"
7+
48
"github.com/ReconfigureIO/cobra"
59
"github.com/ReconfigureIO/reco"
610
"github.com/ReconfigureIO/reco/logger"
711
)
812

9-
var testCmdStart = &cobra.Command{
10-
Use: "run [flags] command -- [args]",
11-
Aliases: []string{"r", "start", "starts", "create"},
12-
Short: "Start a simulation",
13-
Long: `Start a simulation.
14-
Running a hardware simulation checks how your program will build and deploy on hardware.
15-
It's much faster than running a build and is a good way to check for errors in your code.
16-
`,
17-
Run: startTest,
18-
}
13+
var (
14+
testCmdStart = &cobra.Command{
15+
Use: "run [flags] command -- [args]",
16+
Aliases: []string{"r", "start", "starts", "create"},
17+
Short: "Start a simulation",
18+
Long: `Start a simulation.
19+
Running a hardware simulation checks how your program will build and deploy on hardware.
20+
It's much faster than running a build and is a good way to check for errors in your code.
21+
`,
22+
Run: startTest,
23+
}
24+
25+
testCmdLog = &cobra.Command{
26+
Use: fmt.Sprintf("log [simulation_ID]"),
27+
Aliases: []string{"logs"},
28+
Short: fmt.Sprintf("Stream logs for a simulation"),
29+
Long: fmt.Sprintf("Stream logs for a simulation previously started with 'reco sim run'."),
30+
PreRun: testLogPreRun,
31+
Run: func(cmd *cobra.Command, args []string) {
32+
l := reflect.ValueOf(tool).MethodByName("Test").Call(nil)[0].Interface()
33+
if err := l.(reco.Job).Log(args[0], os.Stdout); err != nil {
34+
exitWithError(err)
35+
}
36+
},
37+
}
38+
39+
testLogPreRun = func(cmd *cobra.Command, args []string) {
40+
if len(args) == 0 {
41+
exitWithError("ID required")
42+
}
43+
}
44+
45+
testCmdStop = &cobra.Command{
46+
Use: "stop [simulation_ID]",
47+
Aliases: []string{"s", "stp", "stops"},
48+
Short: fmt.Sprintf("Stop a simulation"),
49+
Long: fmt.Sprintf("Stop a simulation previously started with 'reco sim run'"),
50+
PreRun: testStopPreRun,
51+
Run: func(cmd *cobra.Command, args []string) {
52+
l := reflect.ValueOf(tool).MethodByName("Test").Call(nil)[0].Interface()
53+
if err := l.(reco.Job).Stop(args[0]); err != nil {
54+
exitWithError(err)
55+
}
56+
logger.Std.Printf("Simulation stopped successfully")
57+
},
58+
}
59+
60+
testStopPreRun = func(cmd *cobra.Command, args []string) {
61+
if len(args) == 0 {
62+
exitWithError("ID required")
63+
}
64+
}
65+
)
1966

2067
func init() {
2168
testCmd := genDevCommand("sim", "simulation", "simulation", "simulations", "test", "tests", "t")
2269
testCmd.AddCommand(genListSubcommand("simulations", "Test"))
23-
testCmd.AddCommand(genLogSubcommand("simulation", "Simulation"))
24-
testCmd.AddCommand(genStopSubcommand("simulation", "Simulation"))
70+
testCmd.AddCommand(testCmdLog)
71+
testCmd.AddCommand(testCmdStop)
2572
testCmd.AddCommand(testCmdStart)
2673
testCmd.PersistentFlags().StringVar(&project, "project", project, "Project to use. If unset, the active project is used")
2774

0 commit comments

Comments
 (0)