A bunch of changes

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
Dave Henderson
2018-08-20 20:06:33 -04:00
parent 16a4d2826c
commit a1879b1eb0
16 changed files with 274 additions and 203 deletions

10
cmd/onerng/doc.go Normal file
View File

@ -0,0 +1,10 @@
/*
onerng is a OneRNG hardware random number generation utility.
Usage
TODO...
*/
package main

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"

View File

@ -1,11 +1,12 @@
// onerng: OneRNG hardware random number generation utility
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/hairyhenderson/go-onerng/cmd"
)
func main() {
@ -26,5 +27,10 @@ func main() {
}
}()
cmd.Execute(ctx)
cmd := rootCmd(ctx)
initConfig(ctx, cmd)
if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"
@ -26,7 +26,7 @@ func readCmd(ctx context.Context) *cobra.Command {
Use: "read",
Short: "read some random data from the OneRNG",
RunE: func(cmd *cobra.Command, args []string) error {
o := onerng.OneRNG{Path: opts.Device}
o := &onerng.OneRNG{Path: opts.Device}
err := o.Init(ctx)
if err != nil {
return errors.Wrapf(err, "init failed")

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"
@ -11,7 +11,7 @@ import (
var (
cfgFile string
opts Config
opts config
)
func rootCmd(ctx context.Context) *cobra.Command {
@ -30,19 +30,9 @@ correctly, and that the firmware has not been tampered with.`,
}
}
// Execute -
func Execute(ctx context.Context) {
cmd := rootCmd(ctx)
initConfig(ctx, cmd)
if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func initConfig(ctx context.Context, cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.go-onerng.yaml)")
opts = Config{}
opts = config{}
cmd.PersistentFlags().StringVarP(&opts.Device, "device", "d", "/dev/ttyACM0", "the OneRNG device")
cmd.AddCommand(
@ -69,7 +59,6 @@ func initConfig(ctx context.Context, cmd *cobra.Command) {
}
}
// Config -
type Config struct {
type config struct {
Device string
}

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"bytes"

View File

@ -1,4 +1,4 @@
package cmd
package main
import (
"context"
@ -14,7 +14,7 @@ func versionCmd(ctx context.Context) *cobra.Command {
Use: "version",
Short: "Display the OneRNG's hardware version",
RunE: func(cmd *cobra.Command, args []string) error {
o := onerng.OneRNG{Path: opts.Device}
o := &onerng.OneRNG{Path: opts.Device}
version, err := o.Version(ctx)
if err != nil {
return err