SaveConfiguration 保存评测会话
(userConfirm bool)
| 35 | |
| 36 | // SaveConfiguration 保存评测会话 |
| 37 | func (session *JudgeSession) SaveConfiguration(userConfirm bool) error { |
| 38 | if userConfirm { |
| 39 | fmt.Print("Save all the changed to config file? [y/N] ") |
| 40 | ans := "" |
| 41 | _, err := fmt.Scanf("%s", &ans) |
| 42 | if err != nil { |
| 43 | return nil // don't crash at EOF |
| 44 | } |
| 45 | if len(ans) > 0 && strings.ToLower(ans[:1]) != "y" { |
| 46 | return nil |
| 47 | } |
| 48 | } |
| 49 | err := ioutil.WriteFile(session.ConfigFile, []byte(utils.ObjectToJSONStringFormatted(session.JudgeConfig)), 0644) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | if userConfirm { |
| 54 | fmt.Println("Saved!") |
| 55 | } |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | // NewSession 创建会话对象 |
| 60 | func NewSession(configFile string) (*JudgeSession, error) { |
no test coverage detected