Skip to content

Commit

Permalink
add signout command
Browse files Browse the repository at this point in the history
  • Loading branch information
Gjergj committed Apr 26, 2024
1 parent cb4f72f commit 19f5391
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ sudo dpkg -i testmyapp_0.0.68_amd64.deb
testmyapp signup -u=<your_email_address>
```

#### Login
```bas
testmyapp login -u=<your_email_address>
```

#### Upload your web site
Create an `index.html` file in the current directory and upload it to the project.
```bash
Expand Down Expand Up @@ -66,6 +61,16 @@ testmyapp watch
```
Refresh browser to see changes.

#### Logout
```bash
testmyapp signout
```

#### Login
```bas
testmyapp login -u=<your_email_address>
```

### Update
```bash
brew update
Expand Down
2 changes: 1 addition & 1 deletion cmd/testmyapp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *CustomHTTPClient) Login(username, password string) (string, string, str

// Check the response status
if response.StatusCode != http.StatusOK {
fmt.Printf("HTTP request failed with status code: %d\n", response.StatusCode)
err = fmt.Errorf("HTTP request failed with status code: %d\n", response.StatusCode)
return "", "", "", err
}

Expand Down
16 changes: 16 additions & 0 deletions cmd/testmyapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ func (c *Config) Token(username string) (string, string, string) {
return p.Token, p.UserID, username
}

func (c *Config) Clear(username string) {
//username not specified and more than one account exists
if len(c.Accounts) > 1 && username == "" {
fmt.Println("Please specify an account")
return
}
_, ok := c.Accounts[username]
if !ok {
// return the first account
for k, _ := range c.Accounts {
username = k
}
}
delete(c.Accounts, username)
}

func (c *Config) RefreshToken(username string) (string, string) {
//username not specified and more than one account exists
if len(c.Accounts) > 1 && username == "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/testmyapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
versionCommand(),
deleteCommand(),
signupCommand(),
signoutCommand(),
},
Exec: run,
}
Expand Down
35 changes: 35 additions & 0 deletions cmd/testmyapp/signout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"context"
"flag"
"github.com/peterbourgon/ff/v3/ffcli"
"log"
)

// signout Command creates the "signupCommand" subcommand
func signoutCommand() *ffcli.Command {
c, err := getConfig()
if err != nil {
log.Fatal(err)
}
fs := flag.NewFlagSet("testmyapp signout", flag.ExitOnError)
var (
loginFlags struct {
// Add flags specific to the "login" subcommand
username string
}
)

fs.StringVar(&loginFlags.username, "u", "", "u option for login command")

return &ffcli.Command{
Name: "signout",
ShortUsage: "signout [flags]",
FlagSet: fs,
Exec: func(_ context.Context, args []string) error {
c.Clear(loginFlags.username)
return c.Save()
},
}
}

0 comments on commit 19f5391

Please sign in to comment.