Selaa lähdekoodia

helper func for logged in users

this function checks the host based path for any logged in users and
returns the number or users, a list of usernames and an error if any
pull/36/head
Rob Loranger 4 vuotta sitten
vanhempi
commit
58dd3f985a
No known key found for this signature in database GPG Key ID: D6F1633A4F0903B8
1 muutettua tiedostoa jossa 29 lisäystä ja 0 poistoa
  1. +29
    -0
      cmd/wf/commands.go

+ 29
- 0
cmd/wf/commands.go Näytä tiedosto

@@ -2,6 +2,8 @@ package main


import ( import (
"fmt" "fmt"
"os"
"path/filepath"


"github.com/writeas/writeas-cli/api" "github.com/writeas/writeas-cli/api"
"github.com/writeas/writeas-cli/commands" "github.com/writeas/writeas-cli/commands"
@@ -25,6 +27,33 @@ func requireAuth(f cli.ActionFunc, action string) cli.ActionFunc {
} }
} }


// usersLoggedIn checks for logged in users for the set host flag
// it returns the number of users and a slice of usernames
func usersLoggedIn(c *cli.Context) (int, []string, error) {
path, err := config.UserHostDir(c)
if err != nil {
return 0, nil, err
}
dir, err := os.Open(path)
if err != nil {
return 0, nil, err
}
contents, err := dir.Readdir(0)
if err != nil {
return 0, nil, err
}
var names []string
for _, file := range contents {
if file.IsDir() {
// stat user.json
if _, err := os.Stat(filepath.Join(path, file.Name(), "user.json")); err == nil {
names = append(names, file.Name())
}
}
}
return len(names), names, nil
}

func cmdAuth(c *cli.Context) error { func cmdAuth(c *cli.Context) error {
err := commands.CmdAuth(c) err := commands.CmdAuth(c)
if err != nil { if err != nil {


Ladataan…
Peruuta
Tallenna