refactor(cmd/joj3)!: conf #51
| 
						 | 
					@ -30,7 +30,7 @@ type Conf struct {
 | 
				
			||||||
					Cases   []OptionalCmd
 | 
										Cases   []OptionalCmd
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Parser struct {
 | 
								Parsers []struct {
 | 
				
			||||||
				Name string
 | 
									Name string
 | 
				
			||||||
				With interface{}
 | 
									With interface{}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ import (
 | 
				
			||||||
func generateStages(conf conf.Conf, group string) ([]stage.Stage, error) {
 | 
					func generateStages(conf conf.Conf, group string) ([]stage.Stage, error) {
 | 
				
			||||||
	stages := []stage.Stage{}
 | 
						stages := []stage.Stage{}
 | 
				
			||||||
	existNames := map[string]bool{}
 | 
						existNames := map[string]bool{}
 | 
				
			||||||
	for _, s := range conf.Stages {
 | 
						for _, s := range conf.Stage.Stages {
 | 
				
			||||||
		if s.Group != "" && group != s.Group {
 | 
							if s.Group != "" && group != s.Group {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -50,12 +50,20 @@ func generateStages(conf conf.Conf, group string) ([]stage.Stage, error) {
 | 
				
			||||||
		if len(s.Executor.With.Cases) == 0 {
 | 
							if len(s.Executor.With.Cases) == 0 {
 | 
				
			||||||
			cmds = []stage.Cmd{defaultCmd}
 | 
								cmds = []stage.Cmd{defaultCmd}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							parsers := []stage.StageParser{}
 | 
				
			||||||
 | 
							for _, p := range s.Parsers {
 | 
				
			||||||
 | 
								parsers = append(parsers, stage.StageParser{
 | 
				
			||||||
 | 
									Name: p.Name,
 | 
				
			||||||
 | 
									Conf: p.With,
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		stages = append(stages, stage.Stage{
 | 
							stages = append(stages, stage.Stage{
 | 
				
			||||||
			Name: s.Name,
 | 
								Name: s.Name,
 | 
				
			||||||
			ExecutorName: s.Executor.Name,
 | 
								Executor: stage.StageExecutor{
 | 
				
			||||||
			ExecutorCmds: cmds,
 | 
									Name: s.Executor.Name,
 | 
				
			||||||
			ParserName:   s.Parser.Name,
 | 
									Cmds: cmds,
 | 
				
			||||||
			ParserConf:   s.Parser.With,
 | 
								},
 | 
				
			||||||
 | 
								Parsers: parsers,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	slog.Debug("stages generated", "stages", stages)
 | 
						slog.Debug("stages generated", "stages", stages)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,12 +150,19 @@ func (r ExecutorResult) String() string {
 | 
				
			||||||
	return fmt.Sprintf("%+v", d)
 | 
						return fmt.Sprintf("%+v", d)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type StageExecutor struct {
 | 
				
			||||||
 | 
						Name string
 | 
				
			||||||
 | 
						Cmds []Cmd
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					type StageParser struct {
 | 
				
			||||||
 | 
						Name string
 | 
				
			||||||
 | 
						Conf any
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Stage struct {
 | 
					type Stage struct {
 | 
				
			||||||
	Name     string
 | 
						Name     string
 | 
				
			||||||
	ExecutorName string
 | 
						Executor StageExecutor
 | 
				
			||||||
	ExecutorCmds []Cmd
 | 
						Parsers  []StageParser
 | 
				
			||||||
	ParserName   string
 | 
					 | 
				
			||||||
	ParserConf   any
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ParserResult struct {
 | 
					type ParserResult struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,51 +8,67 @@ import (
 | 
				
			||||||
func Run(stages []Stage) (stageResults []StageResult, err error) {
 | 
					func Run(stages []Stage) (stageResults []StageResult, err error) {
 | 
				
			||||||
	var executorResults []ExecutorResult
 | 
						var executorResults []ExecutorResult
 | 
				
			||||||
	var parserResults []ParserResult
 | 
						var parserResults []ParserResult
 | 
				
			||||||
 | 
						var tmpParserResults []ParserResult
 | 
				
			||||||
	var forceQuit bool
 | 
						var forceQuit bool
 | 
				
			||||||
	slog.Info("stage run start")
 | 
						slog.Info("stage run start")
 | 
				
			||||||
	for _, stage := range stages {
 | 
						for _, stage := range stages {
 | 
				
			||||||
		slog.Info("stage start", "name", stage.Name)
 | 
							slog.Info("stage start", "name", stage.Name)
 | 
				
			||||||
		slog.Info("executor run start", "name", stage.ExecutorName)
 | 
							slog.Info("executor run start", "name", stage.Executor.Name)
 | 
				
			||||||
		slog.Debug("executor run start", "name", stage.ExecutorName,
 | 
							slog.Debug("executor run start", "name", stage.Executor.Name,
 | 
				
			||||||
			"cmds", stage.ExecutorCmds)
 | 
								"cmds", stage.Executor.Cmds)
 | 
				
			||||||
		executor, ok := executorMap[stage.ExecutorName]
 | 
							executor, ok := executorMap[stage.Executor.Name]
 | 
				
			||||||
		if !ok {
 | 
							if !ok {
 | 
				
			||||||
			slog.Error("executor not found", "name", stage.ExecutorName)
 | 
								slog.Error("executor not found", "name", stage.Executor.Name)
 | 
				
			||||||
			err = fmt.Errorf("executor not found: %s", stage.ExecutorName)
 | 
								err = fmt.Errorf("executor not found: %s", stage.Executor.Name)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		executorResults, err = executor.Run(stage.ExecutorCmds)
 | 
							executorResults, err = executor.Run(stage.Executor.Cmds)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			slog.Error("executor run error", "name", stage.ExecutorName, "error", err)
 | 
								slog.Error("executor run error", "name", stage.Executor.Name, "error", err)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		slog.Debug("executor run done", "results", executorResults)
 | 
							slog.Debug("executor run done", "results", executorResults)
 | 
				
			||||||
		for _, executorResult := range executorResults {
 | 
							for _, executorResult := range executorResults {
 | 
				
			||||||
			slog.Debug("executor run done", "result.Files", executorResult.Files)
 | 
								slog.Debug("executor run done", "result.Files", executorResult.Files)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		slog.Info("parser run start", "name", stage.ParserName)
 | 
							parserResults = []ParserResult{}
 | 
				
			||||||
		slog.Debug("parser run start", "name", stage.ParserName,
 | 
							for _, stageParser := range stage.Parsers {
 | 
				
			||||||
			"conf", stage.ParserConf)
 | 
								slog.Info("parser run start", "name", stageParser.Name)
 | 
				
			||||||
		parser, ok := parserMap[stage.ParserName]
 | 
								slog.Debug("parser run start", "name", stageParser.Name,
 | 
				
			||||||
 | 
									"conf", stageParser.Conf)
 | 
				
			||||||
 | 
								parser, ok := parserMap[stageParser.Name]
 | 
				
			||||||
			if !ok {
 | 
								if !ok {
 | 
				
			||||||
			slog.Error("parser not found", "name", stage.ParserName)
 | 
									slog.Error("parser not found", "name", stageParser.Name)
 | 
				
			||||||
			err = fmt.Errorf("parser not found: %s", stage.ParserName)
 | 
									err = fmt.Errorf("parser not found: %s", stageParser.Name)
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		parserResults, forceQuit, err = parser.Run(executorResults, stage.ParserConf)
 | 
								tmpParserResults, forceQuit, err = parser.Run(
 | 
				
			||||||
 | 
									executorResults, stageParser.Conf)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
			slog.Error("parser run error", "name", stage.ParserName, "error", err)
 | 
									slog.Error("parser run error", "name", stageParser.Name, "error", err)
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		slog.Debug("parser run done", "results", parserResults)
 | 
								slog.Debug("parser run done", "results", tmpParserResults)
 | 
				
			||||||
 | 
								if len(parserResults) == 0 {
 | 
				
			||||||
 | 
									parserResults = tmpParserResults
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									for i := range len(parserResults) {
 | 
				
			||||||
 | 
										parserResults[i].Score += tmpParserResults[i].Score
 | 
				
			||||||
 | 
										parserResults[i].Comment += tmpParserResults[i].Comment
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if forceQuit {
 | 
				
			||||||
 | 
									slog.Error("parser force quit", "name", stageParser.Name)
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		stageResults = append(stageResults, StageResult{
 | 
							stageResults = append(stageResults, StageResult{
 | 
				
			||||||
			Name:      stage.Name,
 | 
								Name:      stage.Name,
 | 
				
			||||||
			Results:   parserResults,
 | 
								Results:   parserResults,
 | 
				
			||||||
			ForceQuit: forceQuit,
 | 
								ForceQuit: forceQuit,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		if forceQuit {
 | 
							if forceQuit {
 | 
				
			||||||
			slog.Error("parser force quit", "name", stage.ParserName)
 | 
								break
 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user