-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation in readme and cli
Switches to the urfave/cli/v2 framework for improved cli paramenter documentation. This commit also updates the README.md to make the first usage of this small cli even easier.
- Loading branch information
Showing
8 changed files
with
169 additions
and
53 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/docker/docker/client" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"time" | ||
) | ||
|
||
func Execute(ctx *cli.Context) error { | ||
outputFormat, err := ParseOutputFormat(ctx.String("format")) | ||
|
||
context := DisplayContext{ | ||
Name: ctx.String("container"), | ||
OutputFormat: outputFormat, | ||
} | ||
|
||
dockerClient, err := client.NewEnvClient() | ||
if err != nil { | ||
log.Fatalf("Failed to create environment dockerClient: %s", err) | ||
return err | ||
} | ||
|
||
signalBus := make(chan os.Signal, 1) | ||
signal.Notify(signalBus, os.Interrupt, os.Kill) | ||
|
||
timer := time.NewTicker(ctx.Duration("interval")) | ||
for { | ||
select { | ||
case _ = <-signalBus: | ||
return nil | ||
case _ = <-timer.C: | ||
DisplayCurrentStats(dockerClient, context) | ||
} | ||
} | ||
} |
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
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,54 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"github.com/docker/docker/client" | ||
"github.com/gonvenience/bunt" | ||
"github.com/lynxplay/carre/lib" | ||
"github.com/lynxplay/carre/cmd" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"time" | ||
) | ||
|
||
var ( | ||
container = flag.String("container", "", "-container <container_name>") | ||
interval = flag.Duration("interval", time.Millisecond*500, "-duration 10s") | ||
output = flag.String("output", "CSV", "-output CSV") | ||
) | ||
var version string | ||
|
||
func main() { | ||
flag.Parse() | ||
if "" == *container { | ||
flag.Usage() | ||
_, _ = bunt.Println("Red{-container is required!}") | ||
return | ||
} | ||
mode, err := lib.ParseOutputMode(*output) | ||
if err != nil { | ||
_, _ = bunt.Printf("Orange{WARN: %s}\n", err) | ||
app := &cli.App{ | ||
Name: "carre", | ||
Usage: "Docker process data point collection", | ||
Version: getVersion(), | ||
Action: cmd.Execute, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "container", | ||
Aliases: []string{"C"}, | ||
Usage: "unique container name", | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "format", | ||
Aliases: []string{"F"}, | ||
Value: "JSON", | ||
Usage: "output format of caree", | ||
}, | ||
&cli.DurationFlag{ | ||
Name: "interval", | ||
Aliases: []string{"I"}, | ||
Value: 500 * time.Millisecond, | ||
Usage: "interval between data point collection", | ||
}, | ||
}, | ||
} | ||
app.EnableBashCompletion = true | ||
|
||
context := lib.DisplayContext{ | ||
Name: *container, | ||
OutputMode: mode, | ||
} | ||
|
||
dockerClient, err := client.NewEnvClient() | ||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatalf("Failed to create environment dockerClient: %s", err) | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
signalBus := make(chan os.Signal, 1) | ||
signal.Notify(signalBus, os.Interrupt, os.Kill) | ||
|
||
timer := time.NewTicker(*interval) | ||
for { | ||
select { | ||
case _ = <-signalBus: | ||
return | ||
case _ = <-timer.C: | ||
lib.DisplayCurrentStats(dockerClient, context) | ||
} | ||
func getVersion() string { | ||
if version == "" { | ||
return "develop" | ||
} | ||
return version | ||
} |
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