Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1581 from endocode/dongsu/fleetctl-cobra-cli
Browse files Browse the repository at this point in the history
fleetctl: use cobra instead of cli
  • Loading branch information
Dongsu Park committed May 30, 2016
2 parents 54c7a92 + 235875e commit 6f3df2e
Show file tree
Hide file tree
Showing 76 changed files with 10,420 additions and 521 deletions.
23 changes: 13 additions & 10 deletions fleetctl/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ package main
import (
"fmt"

"github.com/spf13/cobra"

"github.com/coreos/fleet/schema"
)

var (
cmdCatUnit = &Command{
Name: "cat",
Summary: "Output the contents of a submitted unit",
Usage: "UNIT",
Description: `Outputs the unit file that is currently loaded in the cluster. Useful to verify
var cmdCat = &cobra.Command{
Use: "cat UNIT",
Short: "Output the contents of a submitted unit",
Long: `Outputs the unit file that is currently loaded in the cluster. Useful to verify
the correct version of a unit is running.`,
Run: runCatUnit,
}
)
Run: runWrapper(runCatUnit),
}

func init() {
cmdFleet.AddCommand(cmdCat)
}

func runCatUnit(args []string) (exit int) {
func runCatUnit(cCmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
stderr("One unit file must be provided")
return 1
Expand Down
21 changes: 13 additions & 8 deletions fleetctl/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ package main
import (
"time"

"github.com/spf13/cobra"

"github.com/coreos/fleet/client"
)

var cmdDestroyUnit = &Command{
Name: "destroy",
Summary: "Destroy one or more units in the cluster",
Usage: "UNIT...",
Description: `Completely remove one or more running or submitted units from the cluster.
var cmdDestroy = &cobra.Command{
Use: "destroy UNIT...",
Short: "Destroy one or more units in the cluster",
Long: `Completely remove one or more running or submitted units from the cluster.
Instructs systemd on the host machine to stop the unit, deferring to systemd
completely for any custom stop directives (i.e. ExecStop option in the unit
file).
Destroyed units are impossible to start unless re-submitted.`,
Run: runDestroyUnits,
Run: runWrapper(runDestroyUnit),
}

func init() {
cmdFleet.AddCommand(cmdDestroy)
}

func runDestroyUnits(args []string) (exit int) {
func runDestroyUnit(cCmd *cobra.Command, args []string) (exit int) {
if len(args) == 0 {
stderr("No units given")
return 0
Expand All @@ -58,7 +63,7 @@ func runDestroyUnits(args []string) (exit int) {
continue
}

if !sharedFlags.NoBlock {
if sharedFlags.NoBlock {
attempts := sharedFlags.BlockAttempts
retry := func() bool {
if sharedFlags.BlockAttempts < 1 {
Expand Down
8 changes: 4 additions & 4 deletions fleetctl/destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"testing"
)

func doDestroyUnits(r commandTestResults, errchan chan error) {
exit := runDestroyUnits(r.units)
func doDestroyUnits(t *testing.T, r commandTestResults, errchan chan error) {
exit := runDestroyUnit(cmdDestroy, r.units)
if exit != r.expectedExit {
errchan <- fmt.Errorf("%s: expected exit code %d but received %d", r.description, r.expectedExit, exit)
return
Expand Down Expand Up @@ -73,11 +73,11 @@ func TestRunDestroyUnits(t *testing.T) {
wg.Add(2)
go func() {
defer wg.Done()
doDestroyUnits(r, errchan)
doDestroyUnits(t, r, errchan)
}()
go func() {
defer wg.Done()
doDestroyUnits(r, errchan)
doDestroyUnits(t, r, errchan)
}()

go func() {
Expand Down
23 changes: 13 additions & 10 deletions fleetctl/fdforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ import (
"io"
"net"
"os"
)

var (
cmdFDForward = &Command{
Name: "fd-forward",
Summary: "Proxy stdin and stdout to a unix domain socket",
Usage: "SOCKET",
Description: `fleetctl utilizes fd-forward when --tunnel is used and --endpoint is a unix socket. This command is not intended to be called by users directly.`,
Run: runFDForward,
}
"github.com/spf13/cobra"
)

func runFDForward(args []string) (exit int) {
var cmdFDForward = &cobra.Command{
Use: "fd-forward SOCKET",
Short: "Proxy stdin and stdout to a unix domain socket",
Long: `fleetctl utilizes fd-forward when --tunnel is used and --endpoint is a unix socket. This command is not intended to be called by users directly.`,
Run: runWrapper(runFDForward),
}

func init() {
cmdFleet.AddCommand(cmdFDForward)
}

func runFDForward(cCmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
stderr("Provide a single argument")
return 1
Expand Down
Loading

0 comments on commit 6f3df2e

Please sign in to comment.