-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added config utils, dropped not needed config, fixed some naming * fix pr change requests --------- Co-authored-by: Tafseer Khan <[email protected]>
- Loading branch information
1 parent
a7388ae
commit d6e6629
Showing
58 changed files
with
513 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,24 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/taubyte/tau/cli/node" | ||
"github.com/taubyte/tau/config" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Run(args ...string) error { | ||
err := App().Run(args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func App() *cli.App { | ||
func newApp() *cli.App { | ||
app := &cli.App{ | ||
Commands: []*cli.Command{ | ||
startShape(), | ||
startCommand(), | ||
configCommand(), | ||
}, | ||
} | ||
return app | ||
} | ||
|
||
func startShape() *cli.Command { | ||
return &cli.Command{ | ||
Name: "start", | ||
Description: "start a shape", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "shape", | ||
Required: true, | ||
Aliases: []string{"s"}, | ||
}, | ||
&cli.PathFlag{ | ||
Name: "root", | ||
DefaultText: config.DefaultRoot, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "dev-mode", | ||
Aliases: []string{"dev"}, | ||
}, | ||
}, | ||
|
||
Action: func(ctx *cli.Context) error { | ||
protocolConfig, sourceConfig, err := parseSourceConfig(ctx) | ||
if err != nil { | ||
return fmt.Errorf("parsing config failed with: %s", err) | ||
} | ||
|
||
setNetworkDomains(sourceConfig) | ||
return node.Start(ctx.Context, protocolConfig) | ||
}, | ||
func Run(args ...string) error { | ||
err := newApp().Run(args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/pterm/pterm" | ||
"github.com/taubyte/tau/config" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func configCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "config", | ||
Aliases: []string{"cnf", "conf"}, | ||
Description: "configuration utils", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "validate", | ||
Aliases: []string{"check", "ok", "ok?", "valid?"}, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "shape", | ||
Aliases: []string{"s"}, | ||
}, | ||
&cli.PathFlag{ | ||
Name: "root", | ||
DefaultText: config.DefaultRoot, | ||
}, | ||
&cli.PathFlag{ | ||
Name: "path", | ||
Aliases: []string{"p"}, | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
_, _, err := parseSourceConfig(ctx) | ||
return err | ||
}, | ||
}, | ||
{ | ||
Name: "generate", | ||
Aliases: []string{"gen"}, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "shape", | ||
Aliases: []string{"s"}, | ||
}, | ||
&cli.PathFlag{ | ||
Name: "root", | ||
Value: config.DefaultRoot, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "protocols", | ||
Aliases: []string{"proto", "protos"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "network", | ||
Aliases: []string{"fqdn"}, | ||
Value: "example.com", | ||
}, | ||
&cli.IntFlag{ | ||
Name: "p2p-port", | ||
Aliases: []string{"port", "p2p"}, | ||
Value: 4242, | ||
}, | ||
&cli.StringSliceFlag{ | ||
Name: "ip", | ||
Aliases: []string{"address", "addr"}, | ||
}, | ||
&cli.StringSliceFlag{ | ||
Name: "bootstrap", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "swarm-key", | ||
Aliases: []string{"swarm"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "dv-keys", | ||
Aliases: []string{"dv"}, | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
id, err := generateSourceConfig(ctx) | ||
if id != "" { | ||
pterm.Info.Println("ID:", id) | ||
} | ||
return err | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
_ "embed" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
app := newApp() | ||
|
||
ctx, ctxC := context.WithTimeout(context.Background(), time.Second*15) | ||
defer ctxC() | ||
|
||
root, err := os.MkdirTemp("/tmp", "tau-test") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(root) | ||
|
||
os.Mkdir(root+"/storage", 0750) | ||
os.Mkdir(root+"/storage/test", 0750) | ||
os.Mkdir(root+"/config", 0750) | ||
os.Mkdir(root+"/config/keys", 0750) | ||
|
||
err = app.RunContext(ctx, []string{os.Args[0], "cnf", "gen", "-s", "test", "--root", root, "--protos", "auth,seer,monkey", "--swarm-key", "--dv-keys"}) | ||
assert.NilError(t, err) | ||
|
||
err = app.RunContext(ctx, []string{os.Args[0], "cnf", "ok?", "-s", "test", "--root", root}) | ||
assert.NilError(t, err) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ ports: | |
location: | ||
lat: 120 | ||
long: 21 | ||
http-listen: 0.0.0.0:443 | ||
network-url: example.com | ||
domains: | ||
key: | ||
|
File renamed without changes.
Oops, something went wrong.