Expand mockup backend for CLI

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes 2021-03-23 22:41:26 +00:00
parent 661affa4cb
commit 37bf20e24b
6 changed files with 87 additions and 23 deletions

View File

@ -26,13 +26,13 @@ var downCmd = &cobra.Command{
ctx := lg.WithContext(cmd.Context())
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(routeName)
route, err := dagger.LookupRoute(routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}
// TODO: Implement options: --no-cache
if err := route.Down(ctx); err != nil {
if err := route.Down(ctx, nil); err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to up the route")
}
},

View File

@ -33,8 +33,7 @@ var newCmd = &cobra.Command{
routeName := getRouteName(lg, cmd)
// TODO: Implement options: --layout-*, --setup
// FIXME: give route name in create opts
route, err := dagger.CreateRoute(ctx)
route, err := dagger.CreateRoute(ctx, routeName, nil)
if err != nil {
lg.Fatal().Err(err).Msg("failed to create route")
}
@ -42,7 +41,7 @@ var newCmd = &cobra.Command{
if upRoute {
lg.Info().Str("route-id", route.ID).Msg("bringing route online")
if err := route.Up(ctx); err != nil {
if err := route.Up(ctx, nil); err != nil {
lg.Fatal().Err(err).Str("route-id", route.ID).Msg("failed to create route")
}
}

View File

@ -27,14 +27,14 @@ var queryCmd = &cobra.Command{
ctx := lg.WithContext(cmd.Context())
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(routeName)
route, err := dagger.LookupRoute(routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}
expr := args[0]
out, err := route.Query(ctx, expr)
out, err := route.Query(ctx, expr, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to query route")
}

View File

@ -26,13 +26,13 @@ var upCmd = &cobra.Command{
ctx := lg.WithContext(cmd.Context())
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(routeName)
route, err := dagger.LookupRoute(routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}
// TODO: Implement options: --no-cache
if err := route.Up(ctx); err != nil {
if err := route.Up(ctx, nil); err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to up the route")
}
},

View File

@ -135,6 +135,8 @@ func (env *Env) LocalDirs() map[string]string {
if err != nil {
return err
}
// nolint:goconst
// FIXME: merge Env into Route, or fix the linter error
if do != "local" {
return nil
}

View File

@ -10,49 +10,112 @@ import (
type Route struct {
// Globally unique route ID
ID string
// Human-friendly route name.
// A route may have more than one name.
Name string
}
func CreateRoute(ctx context.Context, opts ...CreateOpt) (*Route, error) {
func CreateRoute(ctx context.Context, name string, o *CreateOpts) (*Route, error) {
panic("NOT IMPLEMENTED")
}
type CreateOpt interface{} // FIXME
type CreateOpts struct{}
func DeleteRoute(ctx context.Context, opts ...DeleteOpt) (*Route, error) {
func DeleteRoute(ctx context.Context, o *DeleteOpts) (*Route, error) {
panic("NOT IMPLEMENTED")
}
type DeleteOpt interface{} // FIXME
type DeleteOpts struct{}
func LookupRoute(name string, opts ...LookupOpt) (*Route, error) {
func LookupRoute(name string, o *LookupOpts) (*Route, error) {
panic("NOT IMPLEMENTED")
}
type LookupOpt interface{} // FIXME
type LookupOpts struct{}
func LoadRoute(ctx context.Context, id string, opts ...LoadOpt) (*Route, error) {
func LoadRoute(ctx context.Context, id string, o *LoadOpts) (*Route, error) {
panic("NOT IMPLEMENTED")
}
type LoadOpt interface{} // FIXME
type LoadOpts struct{}
func (r *Route) Up(ctx context.Context, opts ...UpOpt) error {
func (r *Route) Up(ctx context.Context, o *UpOpts) error {
panic("NOT IMPLEMENTED")
}
type UpOpt interface{} // FIXME
type UpOpts struct{}
func (r *Route) Down(ctx context.Context, opts ...DownOpt) error {
func (r *Route) Down(ctx context.Context, o *DownOpts) error {
panic("NOT IMPLEMENTED")
}
type DownOpt interface{} // FIXME
type DownOpts struct{}
func (r *Route) Query(ctx context.Context, expr interface{}, opts ...QueryOpt) (*compiler.Value, error) {
func (r *Route) Query(ctx context.Context, expr interface{}, o *QueryOpts) (*compiler.Value, error) {
panic("NOT IMPLEMENTED")
}
type QueryOpt interface{} // FIXME
type QueryOpts struct{}
func (r *Route) SetLayout(ctx context.Context, a *Artifact) error {
panic("NOT IMPLEMENTED")
}
func (r *Route) Layout() (*Artifact, error) {
panic("NOT IMPLEMENTED")
}
func (r *Route) AddInputArtifact(ctx context.Context, target string, a *Artifact) error {
panic("NOT IMPLEMENTED")
}
func (r *Route) AddInputValue(ctx context.Context, target string, v *compiler.Value) error {
panic("NOT IMPLEMENTED")
}
// FIXME: how does remove work? Does it require a specific file layout?
func (r *Route) RemoveInputs(ctx context.Context, target string) error {
panic("NOT IMPLEMENTED")
}
// FIXME: connect outputs to auto-export values and artifacts.
// An artifact is a piece of data, like a source code checkout,
// binary bundle, container image, database backup etc.
//
// Artifacts can be passed as inputs, generated dynamically from
// other inputs, and received as outputs.
//
// Under the hood, an artifact is encoded as a LLB pipeline, and
// attached to the cue configuration as a
type Artifact struct {
llb interface{}
}
func Dir(path string, include []string) *Artifact {
var llb struct {
Do string
Include []string
}
llb.Do = "local"
llb.Include = include
return &Artifact{
llb: llb,
}
}
func Git(remote, ref, dir string) *Artifact {
panic("NOT IMPLEMENTED")
}
func Container(ref string) *Artifact {
panic("NOT IMPLEMENTED")
}
func LLB(code interface{}) *Artifact {
panic("NOT IMPLEMENTED")
}
// FIXME: manage base
// FIXME: manage inputs