implemented new, up, list

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba
2021-03-25 14:24:05 -07:00
committed by Solomon Hykes
parent 43956e38cc
commit 7ad541feb1
7 changed files with 56 additions and 29 deletions

View File

@@ -2,7 +2,6 @@ package dagger
import (
"context"
"errors"
"fmt"
"io/fs"
"strings"
@@ -311,10 +310,6 @@ func (r *Route) Query(ctx context.Context, expr interface{}, o *QueryOpts) (*com
panic("NOT IMPLEMENTED")
}
func (r *Route) FIXME(ctx context.Context) error {
return errors.New("FIXME")
}
type QueryOpts struct{}
func newTaskFunc(inst *cue.Instance, runner cueflow.RunnerFunc) cueflow.TaskFunc {

View File

@@ -4,8 +4,10 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"os"
"path"
"strings"
"github.com/google/uuid"
)
@@ -67,6 +69,26 @@ func LoadRoute(ctx context.Context, id string, o *LoadOpts) (*Route, error) {
panic("NOT IMPLEMENTED")
}
func ListRoutes(ctx context.Context) ([]string, error) {
routes := []string{}
rootDir := os.ExpandEnv(storeLocation)
files, err := ioutil.ReadDir(rootDir)
if err != nil {
return nil, err
}
for _, f := range files {
if f.IsDir() || !strings.HasSuffix(f.Name(), ".json") {
// There is extra data in the directory, ignore
continue
}
routes = append(routes, f.Name()[:len(f.Name())-5])
}
return routes, nil
}
func routePath(name string) string {
return path.Join(os.ExpandEnv(storeLocation), name+".json")
}