Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: write output files to directory #35

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ go.work

# binary
/bursa

# output files
payment.addr
payment.skey
payment.vkey
seed.txt
stake.addr
stake.skey
stake.vkey
7 changes: 4 additions & 3 deletions cmd/bursa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
fs.Usage = func() {
fmt.Fprintf(
flag.CommandLine.Output(),
"Usage: bursa [-h] [subcommand] [args]\n\nSubcommands:\n\n",
"Usage: bursa [-h] <subcommand> [args]\n\nSubcommands:\n\n",
)
fmt.Fprintf(
flag.CommandLine.Output(),
Expand Down Expand Up @@ -63,9 +63,10 @@ func main() {
}()

var subCommand string
// Parse subcommand (default: "cli")
// Parse subcommand
if len(fs.Args()) < 1 {
subCommand = "cli"
fs.Usage()
os.Exit(1)
} else {
subCommand = fs.Arg(0)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/swaggo/swag v1.16.2
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/zap v1.26.0
golang.org/x/sync v0.1.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
45 changes: 44 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"flag"
"fmt"
"os"
"path/filepath"

"golang.org/x/sync/errgroup"

"github.com/blinklabs-io/bursa"
"github.com/blinklabs-io/bursa/internal/config"
Expand Down Expand Up @@ -58,5 +61,45 @@ func Run() {
fmt.Printf("payment.skey=%s\n", bursa.GetKeyFile(w.PaymentSKey))
fmt.Printf("stake.vkey=%s\n", bursa.GetKeyFile(w.StakeVKey))
fmt.Printf("stake.skey=%s\n", bursa.GetKeyFile(w.StakeSKey))
} // TODO: output to files
} else {
fmt.Printf("Output dir: %v\n", *flagOutput)
_, err := os.Stat(*flagOutput)
if os.IsNotExist(err) {
err = os.MkdirAll(*flagOutput, 0755)
if err != nil {
panic(err)
}
}
var fileMap = []map[string]string{
{"seed.txt": w.Mnemonic},
{"payment.addr": w.PaymentAddress},
{"stake.addr": w.StakeAddress},
{"payment.vkey": bursa.GetKeyFile(w.PaymentVKey)},
{"payment.skey": bursa.GetKeyFile(w.PaymentSKey)},
{"stake.vkey": bursa.GetKeyFile(w.StakeVKey)},
{"stake.skey": bursa.GetKeyFile(w.StakeSKey)},
}
var g errgroup.Group
for _, m := range fileMap {
for k, v := range m {
k := k
v := v
g.Go(func() error {
path := filepath.Join(*flagOutput, k)
err = os.WriteFile(path, []byte(v), 0666)
if err != nil {
return err
}
return err
})
}
}
err = g.Wait()
if err != nil {
logger.Fatalf("error occurred: %s", err)
os.Exit(1)
}
logger.Infof("wrote output files to %s", *flagOutput)

}
}
Loading