feat: create go package

This commit is contained in:
Adrien Waksberg 2019-07-13 11:00:10 +02:00
parent e2513d41bd
commit acbeee688f
9 changed files with 56 additions and 60 deletions

4
cmd/gpm/go.mod Normal file
View file

@ -0,0 +1,4 @@
module git.yaegashi.fr/nishiki/gpm/cmd/gpm
require git.yaegashi.fr/nishiki/gpm v0.0.0
replace git.yaegashi.fr/nishiki/gpm => ../../gpm

24
cmd/gpm/main.go Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2019 Adrien Waksberg
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import(
"git.yaegashi.fr/nishiki/gpm"
)
func main() {
c := gpm.Cli{}
c.Run()
}

View file

@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package gpm
import( import(
"bufio" "bufio"
"flag"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
@ -27,6 +28,20 @@ import(
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
) )
// Options
var(
ADD = flag.Bool("add", false, "add a new entry in the wallet")
UPDATE = flag.Bool("update", false, "update an entry")
DELETE = flag.Bool("delete", false, "delete an entry")
LIST = flag.Bool("list", false, "list the entries in a wallet")
COPY = flag.Bool("copy", false, "enter an copy mode for an entry")
CONFIG = flag.String("config", "", "specify the config file")
GROUP = flag.String("group", "", "search the entries in this group ")
PATTERN = flag.String("pattern", "", "search the entries with this pattern")
WALLET = flag.String("wallet", "", "specify the wallet")
HELP = flag.Bool("help", false, "print this help message")
)
// Cli contain config and wallet to use // Cli contain config and wallet to use
type Cli struct { type Cli struct {
Config Config Config Config
@ -247,14 +262,15 @@ func (c *Cli) copyEntry() {
} }
} }
// Init the cli interface
func (c *Cli) Init() {
c.Config.Load(*CONFIG)
}
// Run the cli interface // Run the cli interface
func (c *Cli) Run() { func (c *Cli) Run() {
if *LIST { c.Config.Load(*CONFIG)
flag.Parse()
if *HELP {
flag.PrintDefaults()
os.Exit(1)
} else if *LIST {
c.listEntry() c.listEntry()
} else if *COPY { } else if *COPY {
c.copyEntry() c.copyEntry()

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package gpm
import ( import (
"encoding/json" "encoding/json"

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package gpm
import( import(
"crypto/aes" "crypto/aes"

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package gpm
import( import(
"fmt" "fmt"

1
gpm/go.mod Normal file
View file

@ -0,0 +1 @@
module git.yaegashi.fr/nishiki/gpm

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package gpm
import ( import (
"encoding/json" "encoding/json"

View file

@ -1,49 +0,0 @@
// Copyright 2019 Adrien Waksberg
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import(
"flag"
"os"
)
// Options
var(
ADD = flag.Bool("add", false, "add a new entry in the wallet")
UPDATE = flag.Bool("update", false, "update an entry")
DELETE = flag.Bool("delete", false, "delete an entry")
LIST = flag.Bool("list", false, "list the entries in a wallet")
COPY = flag.Bool("copy", false, "enter an copy mode for an entry")
CONFIG = flag.String("config", "", "specify the config file")
GROUP = flag.String("group", "", "search the entries in this group ")
PATTERN = flag.String("pattern", "", "search the entries with this pattern")
WALLET = flag.String("wallet", "", "specify the wallet")
HELP = flag.Bool("help", false, "print this help message")
)
func init() {
flag.Parse()
if *HELP {
flag.PrintDefaults()
os.Exit(1)
}
}
func main() {
c := Cli{}
c.Init()
c.Run()
}