move piwigocli from internal to cmd

This commit is contained in:
Celogeek 2021-12-31 11:46:38 +01:00
parent 84b9445e1d
commit 653bf3ffdd
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
18 changed files with 46 additions and 55 deletions

View File

@ -1,4 +1,4 @@
package piwigocli package main
type CategoriesGroup struct { type CategoriesGroup struct {
List CategoriesListCommand `command:"list" description:"List categories"` List CategoriesListCommand `command:"list" description:"List categories"`

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"os" "os"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"net/url" "net/url"

View File

@ -1,4 +1,4 @@
package piwigocli package main
type ImagesGroup struct { type ImagesGroup struct {
List ImagesListCommand `command:"list" description:"List of images"` List ImagesListCommand `command:"list" description:"List of images"`

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/celogeek/piwigo-cli/internal/piwigo"

View File

@ -1,9 +1,28 @@
package main package main
import ( import (
"github.com/celogeek/piwigo-cli/internal/piwigocli" "os"
"github.com/jessevdk/go-flags"
) )
func main() { type Options struct {
piwigocli.Run() }
var options Options
var parser = flags.NewParser(&options, flags.Default)
func main() {
if _, err := parser.Parse(); err != nil {
switch flagsErr := err.(type) {
case flags.ErrorType:
if flagsErr == flags.ErrHelp {
os.Exit(0)
}
os.Exit(1)
default:
os.Exit(1)
}
}
} }

View File

@ -1,4 +1,4 @@
package piwigocli package main
type MethodGroup struct { type MethodGroup struct {
List MethodListCommand `command:"list" description:"List of available methods"` List MethodListCommand `command:"list" description:"List of available methods"`

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package piwigocli package main
type SessionGroup struct { type SessionGroup struct {
Login SessionLoginCommand `command:"login" description:"Initialize a connection to a piwigo instance"` Login SessionLoginCommand `command:"login" description:"Initialize a connection to a piwigo instance"`

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package piwigocli package main
import ( import (
"os" "os"

View File

@ -14,8 +14,8 @@ type Tree interface {
} }
type node struct { type node struct {
Name string Name string
children map[string]*node Nodes map[string]*node
} }
func NewTree() Tree { func NewTree() Tree {
@ -25,13 +25,13 @@ func NewTree() Tree {
} }
func (t *node) Add(name string) Tree { func (t *node) Add(name string) Tree {
if t.children == nil { if t.Nodes == nil {
t.children = map[string]*node{} t.Nodes = map[string]*node{}
} }
n, ok := t.children[name] n, ok := t.Nodes[name]
if !ok { if !ok {
n = &node{Name: name} n = &node{Name: name}
t.children[name] = n t.Nodes[name] = n
} }
return n return n
} }
@ -44,9 +44,9 @@ func (t *node) AddPath(path string) Tree {
} }
func (t *node) Children() []*node { func (t *node) Children() []*node {
childs := make([]*node, len(t.children)) childs := make([]*node, len(t.Nodes))
i := 0 i := 0
for _, n := range t.children { for _, n := range t.Nodes {
childs[i] = n childs[i] = n
i++ i++
} }
@ -57,7 +57,7 @@ func (t *node) Children() []*node {
} }
func (t *node) HasChildren() bool { func (t *node) HasChildren() bool {
return t.children != nil return t.Nodes != nil
} }
func (t *node) FlatView() (out chan string) { func (t *node) FlatView() (out chan string) {

View File

@ -1,28 +0,0 @@
package piwigocli
import (
"os"
"github.com/jessevdk/go-flags"
)
type Options struct {
}
var options Options
var parser = flags.NewParser(&options, flags.Default)
func Run() {
if _, err := parser.Parse(); err != nil {
switch flagsErr := err.(type) {
case flags.ErrorType:
if flagsErr == flags.ErrHelp {
os.Exit(0)
}
os.Exit(1)
default:
os.Exit(1)
}
}
}