diff --git a/cmd/gpm/go.mod b/cmd/gpm/go.mod new file mode 100644 index 0000000..4ea60ea --- /dev/null +++ b/cmd/gpm/go.mod @@ -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 diff --git a/cmd/gpm/main.go b/cmd/gpm/main.go new file mode 100644 index 0000000..23b498a --- /dev/null +++ b/cmd/gpm/main.go @@ -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() +} diff --git a/src/cli.go b/gpm/cli.go similarity index 89% rename from src/cli.go rename to gpm/cli.go index 2b7c4fa..2533b1e 100644 --- a/src/cli.go +++ b/gpm/cli.go @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package gpm import( "bufio" + "flag" "fmt" "os" "strconv" @@ -27,6 +28,20 @@ import( "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 type Cli struct { 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 func (c *Cli) Run() { - if *LIST { + c.Config.Load(*CONFIG) + + flag.Parse() + if *HELP { + flag.PrintDefaults() + os.Exit(1) + } else if *LIST { c.listEntry() } else if *COPY { c.copyEntry() diff --git a/src/config.go b/gpm/config.go similarity index 99% rename from src/config.go rename to gpm/config.go index ea7f73f..75597bd 100644 --- a/src/config.go +++ b/gpm/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package gpm import ( "encoding/json" diff --git a/src/crypto.go b/gpm/crypto.go similarity index 99% rename from src/crypto.go rename to gpm/crypto.go index bd1d188..1df9429 100644 --- a/src/crypto.go +++ b/gpm/crypto.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package gpm import( "crypto/aes" diff --git a/src/entry.go b/gpm/entry.go similarity index 99% rename from src/entry.go rename to gpm/entry.go index d696013..a99f3af 100644 --- a/src/entry.go +++ b/gpm/entry.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package gpm import( "fmt" diff --git a/gpm/go.mod b/gpm/go.mod new file mode 100644 index 0000000..c0ed2e2 --- /dev/null +++ b/gpm/go.mod @@ -0,0 +1 @@ +module git.yaegashi.fr/nishiki/gpm diff --git a/src/wallet.go b/gpm/wallet.go similarity index 99% rename from src/wallet.go rename to gpm/wallet.go index 59a7041..13a7137 100644 --- a/src/wallet.go +++ b/gpm/wallet.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package gpm import ( "encoding/json" diff --git a/src/main.go b/src/main.go deleted file mode 100644 index 70941f4..0000000 --- a/src/main.go +++ /dev/null @@ -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() -}