This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
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.
fix(cli): break commands out into internal package
- Loading branch information
Showing
8 changed files
with
219 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package commands | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Agent() *cli.Command { | ||
return &cli.Command{ | ||
Name: "agent", | ||
Usage: "Starts the aetherfs-agent process", | ||
UsageText: "aetherfs agent [options]", | ||
Description: "The aetherfs-agent process is responsible for managing the local file system.", | ||
Action: func(ctx *cli.Context) error { | ||
log.Print("running agent") | ||
<-ctx.Done() | ||
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,7 @@ | ||
package commands | ||
|
||
import "strings" | ||
|
||
func ExampleString(examples ...string) string { | ||
return strings.Join(examples, "\n ") | ||
} |
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,42 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Pull() *cli.Command { | ||
|
||
return &cli.Command{ | ||
Name: "pull", | ||
Usage: "Pulls a dataset from AetherFS", | ||
UsageText: ExampleString( | ||
"aetherfs pull [options] <path> [dataset...]", | ||
"aetherfs pull /var/datasets maxmind:v1 private.company.io/maxmind:v2", | ||
"aetherfs pull -c path/to/application.afs.yaml /var/datasets", | ||
), | ||
Action: func(ctx *cli.Context) error { | ||
args := ctx.Args().Slice() | ||
|
||
if len(args) == 0 { | ||
return fmt.Errorf("missing path where we should download datasets") | ||
} | ||
|
||
path := args[0] | ||
datasets := args[1:] | ||
|
||
if path == "" { | ||
path, _ = os.Getwd() | ||
} | ||
|
||
for _, dataset := range datasets { | ||
log.Printf("pulling dataset %s", dataset) | ||
} | ||
|
||
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,48 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Push() *cli.Command { | ||
tags := cli.NewStringSlice() | ||
|
||
return &cli.Command{ | ||
Name: "push", | ||
Usage: "Pushes a dataset into AetherFS", | ||
UsageText: ExampleString( | ||
"aetherfs push [options] <path>", | ||
"aetherfs push -t maxmind:v1 -t private.company.io/maxmind:v2 /tmp/maxmind", | ||
), | ||
Flags: []cli.Flag{ | ||
&cli.StringSliceFlag{ | ||
Name: "tag", | ||
Aliases: []string{"t"}, | ||
Usage: "name and optional tag to use for the dataset", | ||
Destination: tags, | ||
Value: tags, | ||
EnvVars: []string{}, | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
path := ctx.Args().Get(0) | ||
|
||
if path == "" { | ||
return fmt.Errorf("missing argument: path") | ||
} | ||
|
||
if len(tags.Value()) == 0 { | ||
return fmt.Errorf("missing option: tag - at least one must be provided") | ||
} | ||
|
||
for _, tag := range tags.Value() { | ||
log.Printf("pushing dataset %s", tag) | ||
} | ||
|
||
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,21 @@ | ||
package commands | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Server() *cli.Command { | ||
return &cli.Command{ | ||
Name: "server", | ||
Usage: "Starts the aetherfs-server process", | ||
UsageText: "aetherfs server [options]", | ||
Description: "The aetherfs-server process is responsible for the datasets in our small blob store.", | ||
Action: func(ctx *cli.Context) error { | ||
log.Print("running server") | ||
<-ctx.Done() | ||
return nil | ||
}, | ||
} | ||
} |
Oops, something went wrong.