mirror of
https://github.com/hairyhenderson/go-onerng.git
synced 2025-07-04 01:22:51 -05:00
A bunch of changes
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
10
cmd/onerng/doc.go
Normal file
10
cmd/onerng/doc.go
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
|
||||
onerng is a OneRNG hardware random number generation utility.
|
||||
|
||||
Usage
|
||||
|
||||
TODO...
|
||||
|
||||
*/
|
||||
package main
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
@ -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
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -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
|
Reference in New Issue
Block a user