fea: openlan: list users filter by network

This commit is contained in:
Daniel Ding
2022-10-18 21:10:31 +08:00
parent 79e830fd56
commit b4c02b049a
5 changed files with 66 additions and 4 deletions

View File

@@ -34,6 +34,16 @@ func (u Lease) List(c *cli.Context) error {
if err := clt.GetJSON(url, &items); err != nil { if err := clt.GetJSON(url, &items); err != nil {
return err return err
} }
name := c.String("network")
if len(name) > 0 {
tmp := items[:0]
for _, obj := range items {
if obj.Network == name {
tmp = append(tmp, obj)
}
}
items = tmp
}
return u.Out(items, c.String("format"), u.Tmpl()) return u.Out(items, c.String("format"), u.Tmpl())
} }
@@ -47,7 +57,10 @@ func (u Lease) Commands(app *api.App) {
Name: "list", Name: "list",
Usage: "Display all lease", Usage: "Display all lease",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Action: u.List, Flags: []cli.Flag{
&cli.StringFlag{Name: "network"},
},
Action: u.List,
}, },
}, },
}) })

View File

@@ -34,6 +34,16 @@ func (u Link) List(c *cli.Context) error {
if err := clt.GetJSON(url, &items); err != nil { if err := clt.GetJSON(url, &items); err != nil {
return err return err
} }
name := c.String("network")
if len(name) > 0 {
tmp := items[:0]
for _, obj := range items {
if obj.Network == name {
tmp = append(tmp, obj)
}
}
items = tmp
}
return u.Out(items, c.String("format"), u.Tmpl()) return u.Out(items, c.String("format"), u.Tmpl())
} }
@@ -47,7 +57,10 @@ func (u Link) Commands(app *api.App) {
Name: "list", Name: "list",
Usage: "Display all links", Usage: "Display all links",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Action: u.List, Flags: []cli.Flag{
&cli.StringFlag{Name: "network"},
},
Action: u.List,
}, },
}, },
}) })

View File

@@ -34,6 +34,16 @@ func (u VPNClient) List(c *cli.Context) error {
if err := clt.GetJSON(url, &items); err != nil { if err := clt.GetJSON(url, &items); err != nil {
return err return err
} }
name := c.String("network")
if len(name) > 0 {
tmp := items[:0]
for _, obj := range items {
if obj.Network == name {
tmp = append(tmp, obj)
}
}
items = tmp
}
return u.Out(items, c.String("format"), u.Tmpl()) return u.Out(items, c.String("format"), u.Tmpl())
} }
@@ -47,7 +57,10 @@ func (u VPNClient) Commands(app *api.App) {
Name: "list", Name: "list",
Usage: "Display all clients", Usage: "Display all clients",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Action: u.List, Flags: []cli.Flag{
&cli.StringFlag{Name: "network"},
},
Action: u.List,
}, },
}, },
}) })

View File

@@ -34,6 +34,16 @@ func (u Point) List(c *cli.Context) error {
if err := clt.GetJSON(url, &items); err != nil { if err := clt.GetJSON(url, &items); err != nil {
return err return err
} }
name := c.String("network")
if len(name) > 0 {
tmp := items[:0]
for _, obj := range items {
if obj.Network == name {
tmp = append(tmp, obj)
}
}
items = tmp
}
return u.Out(items, c.String("format"), u.Tmpl()) return u.Out(items, c.String("format"), u.Tmpl())
} }
@@ -47,7 +57,10 @@ func (u Point) Commands(app *api.App) {
Name: "list", Name: "list",
Usage: "Display all points", Usage: "Display all points",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Action: u.List, Flags: []cli.Flag{
&cli.StringFlag{Name: "network"},
},
Action: u.List,
}, },
}, },
}) })

View File

@@ -74,6 +74,16 @@ func (u User) List(c *cli.Context) error {
if err := clt.GetJSON(url, &items); err != nil { if err := clt.GetJSON(url, &items); err != nil {
return err return err
} }
name := c.String("network")
if len(name) > 0 {
tmp := items[:0]
for _, obj := range items {
if obj.Network == name {
tmp = append(tmp, obj)
}
}
items = tmp
}
return u.Out(items, c.String("format"), u.Tmpl()) return u.Out(items, c.String("format"), u.Tmpl())
} }