Skip to content

Commit

Permalink
Using kong
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 9, 2023
1 parent 234625c commit 581a2c7
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 28 deletions.
29 changes: 27 additions & 2 deletions cli/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package commands

import "github.com/oxisto/money-gopher/cli"
import (
"fmt"

func init() {
kongcompletion "github.com/jotaen/kong-completion"
)

/*func init() {
cli.AddCommand("list-securities", &listSecuritiesCmd{})
cli.AddCommand("update-quote", &triggerQuoteUpdate{})
cli.AddCommand("update-all-quotes", &triggerQuoteUpdateAll{})
Expand All @@ -27,4 +31,25 @@ func init() {
cli.AddCommand("list-portfolios", &listPortfolio{})
cli.AddCommand("portfolio-snapshot", &portfolioSnapshot{})
cli.AddCommand("import-transactions", &importTransactions{})
}*/

type RmCmd struct {
Force bool `help:"Force removal."`
Recursive bool `help:"Recursively remove files."`

Paths []string `arg:"" name:"path" help:"Paths to remove." type:"path"`
}

func (r *RmCmd) Run() error {
fmt.Println("rm", r.Paths)
return nil
}

var CLI struct {
Debug bool `help:"Enable debug mode."`

Rm RmCmd `cmd:"" help:"Remove files."`
Portfolio PortfolioCmd `cmd:"" help:"Portfolio commands."`

Completion kongcompletion.Completion `cmd:"" help:"Outputs shell code for initialising tab completions"`
}
52 changes: 29 additions & 23 deletions cli/commands/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,13 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

type createPortfolio struct{}

func (cmd *createPortfolio) Exec(s *cli.Session, args ...string) {
client := portfoliov1connect.NewPortfolioServiceClient(
http.DefaultClient, "http://localhost:8080",
connect.WithHTTPGet(),
)
res, err := client.CreatePortfolio(
context.Background(),
connect.NewRequest(&portfoliov1.CreatePortfolioRequest{
Portfolio: &portfoliov1.Portfolio{
Name: args[1],
DisplayName: args[2],
},
}),
)
if err != nil {
log.Println(err)
} else {
log.Println(res)
}
type PortfolioCmd struct {
List ListPortfolioCmd `cmd:"" help:"Lists all portfolios."`
}

type listPortfolio struct{}
type ListPortfolioCmd struct{}

func (cmd *listPortfolio) Exec(s *cli.Session, args ...string) {
func (l *ListPortfolioCmd) Run() error {
client := portfoliov1connect.NewPortfolioServiceClient(
http.DefaultClient, "http://localhost:8080",
connect.WithHTTPGet(),
Expand Down Expand Up @@ -104,6 +85,31 @@ func (cmd *listPortfolio) Exec(s *cli.Session, args ...string) {
//out, _ := glamour.Render(in, "dark")
fmt.Println(in)
}

return nil
}

type createPortfolio struct{}

func (cmd *createPortfolio) Exec(s *cli.Session, args ...string) {
client := portfoliov1connect.NewPortfolioServiceClient(
http.DefaultClient, "http://localhost:8080",
connect.WithHTTPGet(),
)
res, err := client.CreatePortfolio(
context.Background(),
connect.NewRequest(&portfoliov1.CreatePortfolioRequest{
Portfolio: &portfoliov1.Portfolio{
Name: args[1],
DisplayName: args[2],
},
}),
)
if err != nil {
log.Println(err)
} else {
log.Println(res)
}
}

func greenOrRed(f float32) string {
Expand Down
26 changes: 23 additions & 3 deletions cmd/mgo/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,30 @@ package main
import (
"os"

"github.com/oxisto/money-gopher/cli"
_ "github.com/oxisto/money-gopher/cli/commands"
"github.com/alecthomas/kong"
kongcompletion "github.com/jotaen/kong-completion"
"github.com/oxisto/money-gopher/cli/commands"
"github.com/posener/complete"
)

func main() {
cli.Run(os.Args)
parser := kong.Must(&commands.CLI,
kong.Name("mgo"),
kong.Description("A shell-like example app."),
kong.UsageOnError(),
)

kongcompletion.Register(parser, predictNames)

// Proceed as normal after kongplete.Complete.
ctx, err := parser.Parse(os.Args[1:])
parser.FatalIfErrorf(err)

err = ctx.Run()
parser.FatalIfErrorf(err)
}

var predictNames = kongcompletion.WithPredictor(
"name",
complete.PredictSet("Ben", "Liz", "Mark", "Sarah"),
)
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ go 1.21

require (
connectrpc.com/connect v1.12.0
github.com/alecthomas/kong v0.8.1
github.com/fatih/color v1.16.0
github.com/jotaen/kong-completion v0.0.5
github.com/mattn/go-sqlite3 v1.14.18
github.com/oxisto/assert v0.0.6
github.com/posener/complete v1.2.3
golang.org/x/net v0.19.0
golang.org/x/text v0.14.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/sys v0.15.0 // indirect
)
35 changes: 35 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
connectrpc.com/connect v1.12.0 h1:HwKdOY0lGhhoHdsza+hW55aqHEC64pYpObRNoAgn70g=
connectrpc.com/connect v1.12.0/go.mod h1:3AGaO6RRGMx5IKFfqbe3hvK1NqLosFNP2BxDYTPmNPo=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/jotaen/kong-completion v0.0.5 h1:IGs/bw0BUMXDSAGooncsUwgg9EXcRNHeindSXApkM00=
github.com/jotaen/kong-completion v0.0.5/go.mod h1:Pic1KtmJkOiWtr9XEVbyWXvn3AuCgv7hH6EykMfDXWE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -15,6 +34,18 @@ github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/oxisto/assert v0.0.6 h1:Z/wRt0qndURRof+eOGr7GbcJ6BHZT2nyZd9diuZHS8o=
github.com/oxisto/assert v0.0.6/go.mod h1:07ANKfyBm6j+pZk1qArFueno6fCoEGKvPbPeJSQkH3s=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab h1:ZjX6I48eZSFetPb41dHudEyVr5v953N15TsNZXlkcWY=
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab/go.mod h1:/PfPXh0EntGc3QAAyUaviy4S9tzy4Zp0e2ilq4voC6E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -27,3 +58,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 581a2c7

Please sign in to comment.