Refactoring indra command.
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/cybriq/proc/pkg/cmds"
|
||||
"github.com/cybriq/proc/pkg/opts/config"
|
||||
"github.com/cybriq/proc/pkg/opts/list"
|
||||
"github.com/cybriq/proc/pkg/opts/meta"
|
||||
)
|
||||
|
||||
var (
|
||||
commands = &cmds.Command{
|
||||
Name: "indra",
|
||||
Description: "Nobody's watching you. Network Freedom.",
|
||||
Documentation: lorem,
|
||||
Entrypoint: defaultHandler,
|
||||
Default: cmds.Tags("help"),
|
||||
Configs: config.Opts{
|
||||
//"AutoPorts": toggle.New(meta.Data{
|
||||
// Label: "Automatic Ports",
|
||||
// Tags: cmds.Tags("node", "wallet"),
|
||||
// Description: "RPC and controller ports are randomized, use with controller for automatic peer discovery",
|
||||
// Documentation: lorem,
|
||||
// Default: "false",
|
||||
//}),
|
||||
},
|
||||
Commands: cmds.Commands{
|
||||
{
|
||||
Name: "version",
|
||||
Description: "print indra version",
|
||||
|
||||
Documentation: lorem,
|
||||
Entrypoint: versionHandler,
|
||||
},
|
||||
{
|
||||
Name: "cli",
|
||||
Description: "a command line client for managing an indra network daemon",
|
||||
|
||||
Documentation: lorem,
|
||||
Entrypoint: cliHandler,
|
||||
},
|
||||
{
|
||||
Name: "serve",
|
||||
Description: "serves an instance of the indra network daemon",
|
||||
Documentation: lorem,
|
||||
Entrypoint: serveHandler,
|
||||
Configs: config.Opts{
|
||||
"seed": list.New(meta.Data{
|
||||
Label: "seed",
|
||||
Description: "Adds additional seeds by hostname, or multiaddress. Examples: seed0.example.com, /ip4/127.0.0.1/tcp/8337",
|
||||
Documentation: lorem,
|
||||
Default: "/ip4/172.16.238.2/tcp/8337",
|
||||
}, func(opt *list.Opt) error {
|
||||
|
||||
return nil
|
||||
}),
|
||||
"listen": list.New(meta.Data{
|
||||
Label: "listen",
|
||||
Description: "A list of listener multiaddresses. Example: /ip4/0.0.0.0/tcp/8337",
|
||||
Documentation: lorem,
|
||||
Default: "/ip4/0.0.0.0/tcp/8337",
|
||||
}, func(opt *list.Opt) error {
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const lorem = `
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
||||
culpa qui officia deserunt mollit anim id est laborum.`
|
||||
@@ -1,48 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Indra-Labs/indra"
|
||||
"github.com/Indra-Labs/indra/pkg/server"
|
||||
"github.com/cybriq/proc/pkg/cmds"
|
||||
log2 "github.com/cybriq/proc/pkg/log"
|
||||
)
|
||||
|
||||
var defaultHandler = func(c *cmds.Command, args []string) error {
|
||||
fmt.Println("indra")
|
||||
return nil
|
||||
}
|
||||
|
||||
var versionHandler = func(c *cmds.Command, args []string) error {
|
||||
fmt.Println(indra.SemVer)
|
||||
return nil
|
||||
}
|
||||
|
||||
var serveHandler = func(c *cmds.Command, args []string) error {
|
||||
|
||||
log.I.Ln("-- ", log2.App, "-" , indra.SemVer, "- Nobody's watching you. Network Freedom. --")
|
||||
|
||||
var err error
|
||||
var srv *server.Server
|
||||
|
||||
log.I.Ln("running serve.")
|
||||
|
||||
if srv, err = server.New(server.DefaultServerConfig); check(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
log.I.Ln("starting the server.")
|
||||
|
||||
if srv.Serve(); check(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
log.I.Ln("-- fin --")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var cliHandler = func(c *cmds.Command, args []string) error {
|
||||
fmt.Println(indra.SemVer)
|
||||
return nil
|
||||
}
|
||||
@@ -1,20 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Indra-Labs/indra"
|
||||
"github.com/Indra-Labs/indra/pkg/server"
|
||||
"github.com/cybriq/proc/pkg/app"
|
||||
"github.com/cybriq/proc/pkg/cmds"
|
||||
log2 "github.com/cybriq/proc/pkg/log"
|
||||
"github.com/cybriq/proc/pkg/opts/config"
|
||||
"github.com/cybriq/proc/pkg/opts/list"
|
||||
"github.com/cybriq/proc/pkg/opts/meta"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
log = log2.GetLogger(indra.PathBase)
|
||||
check = log.E.Chk
|
||||
log = log2.GetLogger(indra.PathBase)
|
||||
check = log.E.Chk
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
func init() {
|
||||
log2.App = "indra"
|
||||
}
|
||||
|
||||
var commands = &cmds.Command{
|
||||
Name: "indra",
|
||||
Description: "Nobody's watching you. Network Freedom.",
|
||||
Documentation: lorem,
|
||||
Default: cmds.Tags("help"),
|
||||
Configs: config.Opts{},
|
||||
Entrypoint: func(c *cmds.Command, args []string) error {
|
||||
|
||||
fmt.Println("indra")
|
||||
|
||||
return nil
|
||||
},
|
||||
Commands: cmds.Commands{
|
||||
{
|
||||
Name: "version",
|
||||
Description: "print indra version",
|
||||
Documentation: lorem,
|
||||
Configs: config.Opts{},
|
||||
Entrypoint: func(c *cmds.Command, args []string) error {
|
||||
|
||||
fmt.Println(indra.SemVer)
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "cli",
|
||||
Description: "a command line client for managing an indra network daemon",
|
||||
Documentation: lorem,
|
||||
Configs: config.Opts{},
|
||||
Entrypoint: func(c *cmds.Command, args []string) error {
|
||||
|
||||
fmt.Println(indra.SemVer)
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "serve",
|
||||
Description: "serves an instance of the indra network daemon",
|
||||
Documentation: lorem,
|
||||
Configs: config.Opts{
|
||||
"seed": list.New(meta.Data{
|
||||
Label: "seed",
|
||||
Description: "Adds additional seeds by hostname, or multiaddress. Examples: seed0.example.com, /ip4/127.0.0.1/tcp/8337",
|
||||
Documentation: lorem,
|
||||
Default: "/ip4/172.16.238.2/tcp/8337",
|
||||
}, func(opt *list.Opt) error {
|
||||
|
||||
return nil
|
||||
}),
|
||||
"listen": list.New(meta.Data{
|
||||
Label: "listen",
|
||||
Description: "A list of listener multiaddresses. Example: /ip4/0.0.0.0/tcp/8337",
|
||||
Documentation: lorem,
|
||||
Default: "/ip4/0.0.0.0/tcp/8337",
|
||||
}, func(opt *list.Opt) error {
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
Entrypoint: func(c *cmds.Command, args []string) error {
|
||||
|
||||
log.I.Ln("-- ", log2.App, "-", indra.SemVer, "- Nobody's watching you. Network Freedom. --")
|
||||
|
||||
var err error
|
||||
var srv *server.Server
|
||||
|
||||
log.I.Ln("running serve.")
|
||||
|
||||
if srv, err = server.New(server.DefaultServerConfig); check(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
log.I.Ln("starting the server.")
|
||||
|
||||
if srv.Serve(); check(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
log.I.Ln("-- fin --")
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var err error
|
||||
var application *app.App
|
||||
@@ -24,10 +120,18 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Launches a new application
|
||||
// Launches the application
|
||||
if err = application.Launch(); check(err) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
const lorem = `
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
||||
culpa qui officia deserunt mollit anim id est laborum.`
|
||||
|
||||
@@ -106,14 +106,17 @@ func (cli *Builder) Push(opts types.ImagePushOptions) (err error) {
|
||||
|
||||
log.I.Ln("pushing tagged images to repository...")
|
||||
|
||||
// Load the docker config
|
||||
|
||||
var file []byte
|
||||
var config *configfile.ConfigFile
|
||||
|
||||
if file, err = ioutil.ReadFile(os.Getenv("INDRA_DOCKER_CONFIG")); check(err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Load the docker config
|
||||
config = configfile.New("config.json")
|
||||
|
||||
config := configfile.New("config.json")
|
||||
config.LoadFromReader(bytes.NewReader(file))
|
||||
|
||||
// Generate a terminal for output
|
||||
@@ -131,9 +134,8 @@ func (cli *Builder) Push(opts types.ImagePushOptions) (err error) {
|
||||
// Generate an authentication token
|
||||
|
||||
authConfigBytes, _ := json.Marshal(auth)
|
||||
authConfigEncoded := base64.URLEncoding.EncodeToString(authConfigBytes)
|
||||
|
||||
opts.RegistryAuth = authConfigEncoded
|
||||
opts.RegistryAuth = base64.URLEncoding.EncodeToString(authConfigBytes)
|
||||
|
||||
// Pushes each tag to the docker repository.
|
||||
for _, tag := range buildOpts.Tags {
|
||||
|
||||
Reference in New Issue
Block a user