refactor(cmd/joj3)!: conf #51
| 
						 | 
					@ -13,28 +13,30 @@ import (
 | 
				
			||||||
	"github.com/koding/multiconfig"
 | 
						"github.com/koding/multiconfig"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ConfStage struct {
 | 
				
			||||||
 | 
						Name     string
 | 
				
			||||||
 | 
						Group    string
 | 
				
			||||||
 | 
						Executor struct {
 | 
				
			||||||
 | 
							Name string
 | 
				
			||||||
 | 
							With struct {
 | 
				
			||||||
 | 
								Default stage.Cmd
 | 
				
			||||||
 | 
								Cases   []OptionalCmd
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						Parsers []struct {
 | 
				
			||||||
 | 
							Name string
 | 
				
			||||||
 | 
							With interface{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Conf struct {
 | 
					type Conf struct {
 | 
				
			||||||
	Name    string `default:"unknown"`
 | 
						Name    string `default:"unknown"`
 | 
				
			||||||
	LogPath string `default:""`
 | 
						LogPath string `default:""`
 | 
				
			||||||
	Stage   struct {
 | 
						Stage   struct {
 | 
				
			||||||
		SandboxExecServer string `default:"localhost:5051"`
 | 
							SandboxExecServer string `default:"localhost:5051"`
 | 
				
			||||||
		SandboxToken      string `default:""`
 | 
							SandboxToken      string `default:""`
 | 
				
			||||||
		OutputPath        string `default:"stages_result.json"`
 | 
							OutputPath        string `default:"joj3_result.json"`
 | 
				
			||||||
		Stages            []struct {
 | 
							Stages            []ConfStage
 | 
				
			||||||
			Name     string
 | 
					 | 
				
			||||||
			Group    string
 | 
					 | 
				
			||||||
			Executor struct {
 | 
					 | 
				
			||||||
				Name string
 | 
					 | 
				
			||||||
				With struct {
 | 
					 | 
				
			||||||
					Default stage.Cmd
 | 
					 | 
				
			||||||
					Cases   []OptionalCmd
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			Parsers []struct {
 | 
					 | 
				
			||||||
				Name string
 | 
					 | 
				
			||||||
				With interface{}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	Teapot struct {
 | 
						Teapot struct {
 | 
				
			||||||
		LogPath         string `default:"/home/tt/.cache/joint-teapot-debug.log"`
 | 
							LogPath         string `default:"/home/tt/.cache/joint-teapot-debug.log"`
 | 
				
			||||||
| 
						 | 
					@ -45,6 +47,29 @@ type Conf struct {
 | 
				
			||||||
		SkipScoreboard  bool   `default:"false"`
 | 
							SkipScoreboard  bool   `default:"false"`
 | 
				
			||||||
		SkipFailedTable bool   `default:"false"`
 | 
							SkipFailedTable bool   `default:"false"`
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// TODO: remove the following backward compatibility fields
 | 
				
			||||||
 | 
						SandboxExecServer string `default:"localhost:5051"`
 | 
				
			||||||
 | 
						SandboxToken      string `default:""`
 | 
				
			||||||
 | 
						OutputPath        string `default:"joj3_result.json"`
 | 
				
			||||||
 | 
						GradingRepoName   string `default:""`
 | 
				
			||||||
 | 
						SkipTeapot        bool   `default:"true"`
 | 
				
			||||||
 | 
						ScoreboardPath    string `default:"scoreboard.csv"`
 | 
				
			||||||
 | 
						FailedTablePath   string `default:"failed-table.md"`
 | 
				
			||||||
 | 
						Stages            []struct {
 | 
				
			||||||
 | 
							Name     string
 | 
				
			||||||
 | 
							Group    string
 | 
				
			||||||
 | 
							Executor struct {
 | 
				
			||||||
 | 
								Name string
 | 
				
			||||||
 | 
								With struct {
 | 
				
			||||||
 | 
									Default stage.Cmd
 | 
				
			||||||
 | 
									Cases   []OptionalCmd
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							Parser struct {
 | 
				
			||||||
 | 
								Name string
 | 
				
			||||||
 | 
								With interface{}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type OptionalCmd struct {
 | 
					type OptionalCmd struct {
 | 
				
			||||||
| 
						 | 
					@ -134,6 +159,25 @@ func parseConfFile(path string) (conf Conf, err error) {
 | 
				
			||||||
		slog.Error("validate stages conf", "error", err)
 | 
							slog.Error("validate stages conf", "error", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// TODO: remove the following backward compatibility codes
 | 
				
			||||||
 | 
						conf.Stage.SandboxExecServer = conf.SandboxExecServer
 | 
				
			||||||
 | 
						conf.Stage.SandboxToken = conf.SandboxToken
 | 
				
			||||||
 | 
						conf.Stage.OutputPath = conf.OutputPath
 | 
				
			||||||
 | 
						conf.Stage.Stages = make([]ConfStage, len(conf.Stages))
 | 
				
			||||||
 | 
						for i, stage := range conf.Stages {
 | 
				
			||||||
 | 
							conf.Stage.Stages[i].Name = stage.Name
 | 
				
			||||||
 | 
							conf.Stage.Stages[i].Group = stage.Group
 | 
				
			||||||
 | 
							conf.Stage.Stages[i].Executor = stage.Executor
 | 
				
			||||||
 | 
							conf.Stage.Stages[i].Parsers = []struct {
 | 
				
			||||||
 | 
								Name string
 | 
				
			||||||
 | 
								With interface{}
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name: stage.Parser.Name,
 | 
				
			||||||
 | 
									With: stage.Parser.With,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user