From d2269fca0043e410c24af7ae535c91a9d5f7f848 Mon Sep 17 00:00:00 2001 From: the-redback Date: Sat, 16 May 2020 03:55:16 +0600 Subject: [PATCH] Added debugging before script --- cf.go | 4 +++- cmd/args.go | 1 + cmd/test.go | 9 ++++++++- config/config.go | 17 +++++++++-------- config/template.go | 5 ++++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/cf.go b/cf.go index 44290328..0b4458aa 100644 --- a/cf.go +++ b/cf.go @@ -33,7 +33,7 @@ Usage: cf list [...] cf parse [...] cf gen [] - cf test [] + cf test [-d] [] cf watch [all] [...] cf open [...] cf stand [...] @@ -48,6 +48,7 @@ Options: --version Show version. -f , --file , Path to file. E.g. "a.cpp", "./temp/a.cpp" + -d --debug Run with debugging before script. Any useful text. E.g. "https://codeforces.com/contest/100", "https://codeforces.com/contest/180/problem/A", @@ -85,6 +86,7 @@ Examples: test all samples. If you want to add a new testcase, create two files "inK.txt" and "ansK.txt" where K is a string with 0~9. + cf test -d Run with debugging before script cf watch Watch the first 10 submissions of current contest. cf watch all Watch all submissions of current contest. cf open 1136a Use default web browser to open the page of contest diff --git a/cmd/args.go b/cmd/args.go index 9e9c8b6b..56d52f0c 100644 --- a/cmd/args.go +++ b/cmd/args.go @@ -19,6 +19,7 @@ type ParsedArgs struct { Alias string `docopt:""` Accepted bool `docopt:"ac"` All bool `docopt:"all"` + Debug bool `docopt:"--debug"` Handle string `docopt:""` Version string `docopt:"{version}"` Config bool `docopt:"config"` diff --git a/cmd/test.go b/cmd/test.go index 072c9316..f07fc9be 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -188,7 +188,14 @@ func Test() (err error) { return nil } - if err = run(template.BeforeScript); err != nil { + beforeScript := template.BeforeScript + if Args.Debug { + if template.DbgBeforeScript==""{ + return errors.New("debugging_before_script is not set in ~/.cf/config") + } + beforeScript = template.DbgBeforeScript + } + if err = run(beforeScript); err != nil { return } if s := filter(template.Script); len(s) > 0 { diff --git a/config/config.go b/config/config.go index e2f4bef7..ee2b85bb 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,10 @@ package config import ( + "bytes" "encoding/json" "io/ioutil" "os" - "bytes" "path/filepath" "github.com/fatih/color" @@ -13,13 +13,14 @@ import ( // CodeTemplate config parse code template type CodeTemplate struct { - Alias string `json:"alias"` - Lang string `json:"lang"` - Path string `json:"path"` - Suffix []string `json:"suffix"` - BeforeScript string `json:"before_script"` - Script string `json:"script"` - AfterScript string `json:"after_script"` + Alias string `json:"alias"` + Lang string `json:"lang"` + Path string `json:"path"` + Suffix []string `json:"suffix"` + BeforeScript string `json:"before_script"` + DbgBeforeScript string `json:"debugging_before_script"` + Script string `json:"script"` + AfterScript string `json:"after_script"` } // Config load and save configuration diff --git a/config/template.go b/config/template.go index d5a53b56..ed474801 100644 --- a/config/template.go +++ b/config/template.go @@ -118,12 +118,15 @@ func (c *Config) AddTemplate() (err error) { color.Red("Script can not be empty. Please input again: ") } + color.Cyan(`Debugging before script (e.g. "g++ $%full%$ -o $%file%$.exe -std=c++11 -Donline_judge"), empty is ok: `) + dbgBeforeScript := util.ScanlineTrim() + color.Cyan(`After script (e.g. "rm $%file%$.exe" or "cmd.exe /C del $%file%$.exe" in windows), empty is ok: `) afterScript := util.ScanlineTrim() c.Template = append(c.Template, CodeTemplate{ alias, lang, path, suffix, - beforeScript, script, afterScript, + beforeScript, dbgBeforeScript, script, afterScript, }) if util.YesOrNo("Make it default (y/n)? ") {