Skip to content

Commit

Permalink
Merge pull request #12 from z4yx/campus-only
Browse files Browse the repository at this point in the history
Add persistent option in config file for campus-only
  • Loading branch information
z4yx authored Oct 16, 2020
2 parents 007789f + f75be70 commit b7cf738
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ USAGE:
auth-thu [options] online [online_options]
VERSION:
2.0.0
2.0.1
AUTHORS:
Yuxiang Zhang <[email protected]>
Expand Down Expand Up @@ -87,7 +87,8 @@ The default location of config file is `~/.auth-thu`.
"noCheck": false,
"insecure": false,
"daemonize": false,
"acId": ""
"acId": "",
"campusOnly": false
}
```

Expand Down
7 changes: 5 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Settings struct {
Daemon bool `json:"daemonize"`
Debug bool `json:"debug"`
AcID string `json:"acId"`
Campus bool `json:"campusOnly"`
}

var logger = loggo.GetLogger("auth-thu")
Expand Down Expand Up @@ -91,6 +92,7 @@ func mergeCliSettings(c *cli.Context) error {
if len(merged.AcID) == 0 {
merged.AcID = settings.AcID
}
merged.Campus = settings.Campus || c.Bool("campus-only")
settings = merged
logger.Debugf("Settings Username: \"%s\"\n", settings.Username)
logger.Debugf("Settings Ip: \"%s\"\n", settings.Ip)
Expand All @@ -103,6 +105,7 @@ func mergeCliSettings(c *cli.Context) error {
logger.Debugf("Settings Daemon: %t\n", settings.Daemon)
logger.Debugf("Settings Debug: %t\n", settings.Debug)
logger.Debugf("Settings AcID: \"%s\"\n", settings.AcID)
logger.Debugf("Settings Campus: %t\n", settings.Campus)
return nil
}

Expand Down Expand Up @@ -312,7 +315,7 @@ func cmdAuthUtil(c *cli.Context, logout bool) error {
}
}

if c.Bool("campus-only") {
if settings.Campus {
settings.Username += "@tsinghua"
}

Expand Down Expand Up @@ -406,7 +409,7 @@ func main() {
auth-thu [options] logout
auth-thu [options] online [online_options]`,
Usage: "Authenticating utility for Tsinghua",
Version: "2.0.0",
Version: "2.0.1",
HideHelp: true,
Flags: []cli.Flag{
&cli.StringFlag{Name: "username, u", Usage: "your TUNET account `name`"},
Expand Down

0 comments on commit b7cf738

Please sign in to comment.