2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-06 03:20:21 +00:00
lntop/cli/cli.go
Edouard f72c5ca099
V0.1.0 (#10)
* config: add Views

* refac views channels

* fix config default

* views: menu

* config default: add comment

* fix config default

* README: enhance config section

* fix README

* controller: F2 Menu

* views: transactions

* fix views: set current in layout

* fix menu

* ft transactions

* fix Help

* fix controller Menu

* view: transaction

* refac controller

* fix ui controller

* try some bold

* fix cursor

* refac color

* focus column transactions

* controller: add keyBinding Menu m

* help view: add menu

* fix cursor: push to the right

* refac remove current model

* ui: txs and channels sortable

* fix focus column

* view transaction: transaction dest addresses

* fix menu

* refac controller

* channels: sort

* rename current column

* refac cursor

* refac currentColumnIndex

* set cursor if view deleted

* remove previous

* clean view.View

* controller: ToggleView

* fix menu

* view txs: add config

* feat order

* fix channels sort
* feat transactions sort
* feat help: add asc/desc
* fix README
* color: magenta
* fix color
* fix views menu
* fix views help
* network backend: SubscribeTransactions
* pubsub: transactions
* controller.Listen: refresh transactions
* fix controller
* fix controller pubsub: no need for wallet ticker
* fix models transactions
* views channels: column SENT and RECEIVED
* update version
* fix README
* fix README
* fix models sort
* fix readme and default config
* fix readme
2019-05-14 18:13:59 +02:00

102 lines
1.8 KiB
Go

package cli
import (
"context"
"os"
"os/signal"
cli "gopkg.in/urfave/cli.v2"
"github.com/edouardparis/lntop/app"
"github.com/edouardparis/lntop/config"
"github.com/edouardparis/lntop/events"
"github.com/edouardparis/lntop/logging"
"github.com/edouardparis/lntop/pubsub"
"github.com/edouardparis/lntop/ui"
)
const version = "v0.1.0"
// New creates a new cli app.
func New() *cli.App {
cli.VersionFlag = &cli.BoolFlag{
Name: "version", Aliases: []string{},
Usage: "print the version",
}
return &cli.App{
Name: "lntop",
Version: version,
EnableShellCompletion: true,
Action: run,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "path to config file",
},
},
Commands: []*cli.Command{
{
Name: "pubsub",
Aliases: []string{""},
Usage: "run the pubsub only",
Action: pubsubRun,
},
},
}
}
func run(c *cli.Context) error {
cfg, err := config.Load(c.String("config"))
if err != nil {
return err
}
app, err := app.New(cfg)
if err != nil {
return err
}
ctx := context.Background()
events := make(chan *events.Event)
ps := pubsub.New(app.Logger, app.Network)
go func() {
err := ui.Run(ctx, app, events)
if err != nil {
app.Logger.Debug("ui", logging.String("error", err.Error()))
}
ps.Stop()
}()
ps.Run(ctx, events)
return nil
}
func pubsubRun(c *cli.Context) error {
cfg, err := config.Load(c.String("config"))
if err != nil {
return err
}
app, err := app.New(cfg)
if err != nil {
return err
}
events := make(chan *events.Event)
ps := pubsub.New(app.Logger, app.Network)
ps.Run(context.Background(), events)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
go func() {
<-sig
ps.Stop()
}()
return nil
}