Skip to content

Commit

Permalink
Change username -> handle/email. Simplify the project framework. Close
Browse files Browse the repository at this point in the history
  • Loading branch information
xalanq committed Feb 27, 2020
1 parent bd02c4a commit da57241
Show file tree
Hide file tree
Showing 31 changed files with 424 additions and 401 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ It's fast, small, cross-platform and powerful.
* Generate codes from the specified template (including timestamp, author, etc.)
* List problems' stats of one contest/gym.
* Use default web browser to open problems' pages, standings' page, etc.
* Setup a network proxy.
* Colorful CLI.

Pull requests are always welcome.
Expand All @@ -35,14 +36,16 @@ Pull requests are always welcome.

You can download the pre-compiled binary file in [here](https://github.com/xalanq/cf-tool/releases).

Or you can compile it from the source (go >= 1.12):
Or you can compile it from the source **(go >= 1.12)**:

```plain
$ git clone https://github.com/xalanq/cf-tool
$ cd cf-tool
$ go get github.com/xalanq/cf-tool
$ cd $GOPATH/src/github.com/xalanq/cf-tool
$ go build -ldflags "-s -w" cf.go
```

If you don't know what's the `$GOPATH`, please see here <https://github.com/golang/go/wiki/GOPATH>.

## Usage

Let's simulate a competition.
Expand Down Expand Up @@ -84,7 +87,7 @@ List problems' stats of the contest.
Open the standings' page of the contest.

```plain
You should run "cf config" to configure your username, password and the code template at first.
You should run "cf config" to configure your handle, password and the code template at first.
If you want to compete, the best command is "cf race 1111" where "1111" is the contest id.
Expand All @@ -101,7 +104,7 @@ Usage:
cf sid [<submission-id>] [<contest-id>]
cf race <contest-id>
cf pull [ac] [<contest-id>] [<problem-id>]
cf clone [ac] <username>
cf clone [ac] <handle>
cf upgrade
Examples:
Expand Down Expand Up @@ -129,7 +132,7 @@ Examples:
cf sid 52531875 Use default web browser to open the submission 52531875's page.
cf sid Open the last submission's page.
cf race 1136 If the contest 1136 has not started yet, it will countdown. When the
countdown ends, it will open dashboard and problems' pages, and parse samples.
countdown ends, it will open all problems' pages and parse samples.
cf pull 100 Pull all problems' latest codes of contest 100 into "./100/<problem-id>".
cf pull 100 a Pull the latest code of problem "a" of contest 100 into "./100/<problem-id>".
cf pull ac 100 a Pull the "Accepted" or "Pretests passed" code of problem "a" of contest 100.
Expand All @@ -146,16 +149,16 @@ Notes:
File:
cf will save some data in some files:
"~/.cfconfig" Configuration file, including username, encrypted password, etc.
"~/.cfsession" Session file, including cookies, username, etc.
"~/.cf/config" Configuration file, including templates, etc.
"~/.cf/session" Session file, including cookies, handle, password, etc.
"~" is the home directory of current user in your system.
Template:
You can insert some placeholders into your template code. When generate a code from the
template, cf will replace all placeholders by following rules:
$%U%$ Username
$%U%$ Handle (e.g. xalanq)
$%Y%$ Year (e.g. 2019)
$%M%$ Month (e.g. 04)
$%D%$ Day (e.g. 09)
Expand Down Expand Up @@ -189,7 +192,7 @@ Options:
The placeholders inside the template will be replaced with the corresponding content when you run `cf gen`.

```
$%U%$ Username
$%U%$ Handle (e.g. xalanq)
$%Y%$ Year (e.g. 2019)
$%M%$ Month (e.g. 04)
$%D%$ Day (e.g. 09)
Expand Down
41 changes: 22 additions & 19 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Codeforces Tool 是 [Codeforces](https://codeforces.com) 的命令行界面的
* 从指定模板生成代码(包括时间戳,作者等信息)
* 列出某场比赛的所有题目的整体信息
* 用默认的网页浏览器打开题目页面、榜单、提交页面等
* 设置网络代理
* 丰富多彩的命令行

欢迎大家一起完善这个工具呀,欢迎Pull requests。
Expand All @@ -38,11 +39,13 @@ Codeforces Tool 是 [Codeforces](https://codeforces.com) 的命令行界面的
或者你可以把整个 repo 给 clone 下来,然后自己编译 (go >= 1.12):

```plain
$ git clone https://github.com/xalanq/cf-tool
$ cd cf-tool
$ go get github.com/xalanq/cf-tool
$ cd $GOPATH/src/github.com/xalanq/cf-tool
$ go build -ldflags "-s -w" cf.go
```

如果你不知道 `$GOPATH` 是什么,请看一下这篇文章 <https://github.com/golang/go/wiki/GOPATH>.

## 使用方法

以下简单模拟一场比赛的流程。
Expand Down Expand Up @@ -99,7 +102,7 @@ $ go build -ldflags "-s -w" cf.go
cf sid [<submission-id>] [<contest-id>]
cf race <contest-id>
cf pull [ac] [<contest-id>] [<problem-id>]
cf clone [ac] <username>
cf clone [ac] <handle>
cf upgrade
例子:
Expand Down Expand Up @@ -143,21 +146,21 @@ $ go build -ldflags "-s -w" cf.go
储存的文件:
cf 会保存数据到以下文件:
"~/.cfconfig" 这是配置文件,包括用户名、加密后的密码等
"~/.cfsession" 这是会话文件,包括 cookies、用户名等
"~/.cf/config" 这是配置文件。
"~/.cf/session" 这是会话文件,包括 cookies、用户名、密码等
"~" 这个符号是系统当前用户的主文件夹。
模板:
你可以在你的代码里插入一些标识符,当用 cf 生成代码的时候,标识符会按照以下规则替换:
$%U%$ 用户名
$%Y%$ 年 (e.g. 2019)
$%M%$ 月 (e.g. 04)
$%D%$ 日 (e.g. 09)
$%h%$ 时 (e.g. 08)
$%m%$ 分 (e.g. 05)
$%s%$ 秒 (e.g. 00)
$%U%$ 用户名 (例如 xalanq)
$%Y%$ 年 (例如 2019)
$%M%$ 月 (例如 04)
$%D%$ 日 (例如 09)
$%h%$ 时 (例如 08)
$%m%$ 分 (例如 05)
$%s%$ 秒 (例如 00)
模板内的脚本:
模板支持三个脚本命令,当使用 "cf test" 时会依次执行:
Expand All @@ -184,13 +187,13 @@ Options:
当这份模板被 `cf gen` 生成时,模板内部的占位符会替换成相应的内容。

```
$%U%$ 用户名
$%Y%$ 年 (e.g. 2019)
$%M%$ 月 (e.g. 04)
$%D%$ 日 (e.g. 09)
$%h%$ 时 (e.g. 08)
$%m%$ 分 (e.g. 05)
$%s%$ 秒 (e.g. 00)
$%U%$ 用户名 (例如 xalanq)
$%Y%$ 年 (例如 2019)
$%M%$ 月 (例如 04)
$%D%$ 日 (例如 09)
$%h%$ 时 (例如 08)
$%m%$ 分 (例如 05)
$%s%$ 秒 (例如 00)
```

```cpp
Expand Down
20 changes: 14 additions & 6 deletions cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/fatih/color"
ansi "github.com/k0kubun/go-ansi"
"github.com/mitchellh/go-homedir"
"github.com/xalanq/cf-tool/client"
"github.com/xalanq/cf-tool/cmd"
"github.com/xalanq/cf-tool/config"

Expand All @@ -14,10 +16,13 @@ import (

const version = "v0.9.0"

var configPath = "~/.cf/config"
var sessionPath = "~/.cf/session"

func main() {
usage := `Codeforces Tool $%version%$ (cf). https://github.com/xalanq/cf-tool
You should run "cf config" to configure your username, password and the code template at first.
You should run "cf config" to configure your handle, password and the code template at first.
If you want to compete, the best command is "cf race 1111" where "1111" is the contest id.
Expand All @@ -34,7 +39,7 @@ Usage:
cf sid [<submission-id>] [<contest-id>]
cf race <contest-id>
cf pull [ac] [<contest-id>] [<problem-id>]
cf clone [ac] <username>
cf clone [ac] <handle>
cf upgrade
Examples:
Expand Down Expand Up @@ -79,16 +84,16 @@ Notes:
File:
cf will save some data in some files:
"~/.cfconfig" Configuration file, including username, encrypted password, etc.
"~/.cfsession" Session file, including cookies, username, etc.
"~/.cf/config" Configuration file, including templates, etc.
"~/.cf/session" Session file, including cookies, handle, password, etc.
"~" is the home directory of current user in your system.
Template:
You can insert some placeholders into your template code. When generate a code from the
template, cf will replace all placeholders by following rules:
$%U%$ Username
$%U%$ Handle (e.g. xalanq)
$%Y%$ Year (e.g. 2019)
$%M%$ Month (e.g. 04)
$%D%$ Day (e.g. 09)
Expand Down Expand Up @@ -120,7 +125,10 @@ Options:
args, _ := docopt.Parse(usage, nil, true, fmt.Sprintf("Codeforces Tool (cf) %v", version), false)
args[`{version}`] = version
color.Output = ansi.NewAnsiStdout()
config.Init()
configPath, _ = homedir.Expand(configPath)
sessionPath, _ = homedir.Expand(sessionPath)
config.Init(configPath)
client.Init(sessionPath, config.Instance.Host, config.Instance.Proxy)
err := cmd.Eval(args)
if err != nil {
color.Red(err.Error())
Expand Down
Loading

0 comments on commit da57241

Please sign in to comment.