Start laying out the structure of gooni
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/cli/version"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
// Run the app. This is the main app entry point
|
||||
func Run() error {
|
||||
util.Log("Running")
|
||||
root.Cmd.Version(version.Version)
|
||||
_, err := root.Cmd.Parse(os.Args[1:])
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("info", "Display information about OONI Probe")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Info")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("list", "List measurements")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Listing")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package nettest
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("nettest", "Run a specific nettest")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Nettest")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package root
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
// Cmd is the root command
|
||||
var Cmd = kingpin.New("ooni", "")
|
||||
|
||||
// Command is syntax sugar for defining sub-commands
|
||||
var Command = Cmd.Command
|
||||
|
||||
func init() {
|
||||
Cmd.PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
util.Log("Running pre-action")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("run", "Run a test group or OONI Run link")
|
||||
|
||||
nettestGroup := cmd.Arg("name", "the nettest group to run").Required().String()
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Starting %s", nettestGroup)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package nettest
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("show", "Show a specific measurement")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Show")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("upload", "Upload a specific measurement")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Uploading")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
)
|
||||
|
||||
const Version = "0.0.1"
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("version", "Show version.")
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
fmt.Println(Version)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package colors
|
||||
|
||||
import (
|
||||
color "github.com/aybabtme/rgbterm"
|
||||
)
|
||||
|
||||
// Gray string.
|
||||
func Gray(s string) string {
|
||||
return color.FgString(s, 150, 150, 150)
|
||||
}
|
||||
|
||||
// Blue string.
|
||||
func Blue(s string) string {
|
||||
return color.FgString(s, 77, 173, 247)
|
||||
}
|
||||
|
||||
// Cyan string.
|
||||
func Cyan(s string) string {
|
||||
return color.FgString(s, 34, 184, 207)
|
||||
}
|
||||
|
||||
// Green string.
|
||||
func Green(s string) string {
|
||||
return color.FgString(s, 0, 200, 255)
|
||||
}
|
||||
|
||||
// Red string.
|
||||
func Red(s string) string {
|
||||
return color.FgString(s, 194, 37, 92)
|
||||
}
|
||||
|
||||
// Yellow string.
|
||||
func Yellow(s string) string {
|
||||
return color.FgString(s, 252, 196, 25)
|
||||
}
|
||||
|
||||
// Purple string.
|
||||
func Purple(s string) string {
|
||||
return color.FgString(s, 96, 97, 190)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/openobservatory/gooni/internal/colors"
|
||||
)
|
||||
|
||||
// Log outputs a log message.
|
||||
func Log(msg string, v ...interface{}) {
|
||||
fmt.Printf(" %s\n", colors.Purple(fmt.Sprintf(msg, v...)))
|
||||
}
|
||||
|
||||
// Fatal error
|
||||
func Fatal(err error) {
|
||||
fmt.Fprintf(os.Stderr, "\n %s %s\n\n", colors.Red("Error:"), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user