Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jun 8, 2018
1 parent b4c5bda commit 85e221c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ LDFLAGS:=-ldflags '-X github.com/fossas/fossa-cli/cmd/fossa/version.version=$(sh
all: build

$(DEP):
go get github.com/golang/dep/cmd/dep
[ -f $@ ] || go get -u github.com/golang/dep/cmd/dep

$(GO_BINDATA):
go get github.com/go-bindata/go-bindata/...
[ -f $@ ] || go get -u github.com/go-bindata/go-bindata/...

$(STRINGER):
go get golang.org/x/tools/cmd/stringer
[ -f $@ ] || go get -u golang.org/x/tools/cmd/stringer

.PHONY: build
build: $(BIN)/fossa
Expand Down
11 changes: 6 additions & 5 deletions cmd/fossa/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ var (
)

var Cmd = cli.Command{
Name: "build",
Usage: "Run a default project build",
Action: Run,
Flags: flags.WithGlobalFlags([]cli.Flag{
Name: "build",
Usage: "Run a default project build",
Action: Run,
ArgsUsage: "MODULE",
Flags: flags.WithGlobalFlags(flags.WithModulesFlags([]cli.Flag{
cli.BoolFlag{Name: Clean, Usage: "clean artifacts before building"},
cli.BoolFlag{Name: Force, Usage: "rebuild module even if it appears to already be built"},
}),
})),
}

var _ cli.ActionFunc = Run
Expand Down
2 changes: 1 addition & 1 deletion cmd/fossa/cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Cmd = cli.Command{
Name: "upload",
Usage: "Uploads user-provided test results to FOSSA",
Action: Run,
ArgsUsage: "<data>",
ArgsUsage: "DATA",
Flags: flags.WithGlobalFlags([]cli.Flag{
cli.BoolFlag{Name: "l, locators", Usage: "upload data in locator format (instead of JSON)"},
}),
Expand Down
10 changes: 10 additions & 0 deletions cmd/fossa/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ var (
DebugF = cli.BoolFlag{Name: Debug, Usage: "print debug information to stderr"}
)

func WithModulesFlags(f []cli.Flag) []cli.Flag {
return append(f, Modules...)
}

var (
Modules = []cli.Flag{OptionF}
Option = "option"
OptionF = cli.StringSliceFlag{Name: Option, Usage: "options for the module (format is `key:value` e.g. allow-unresolved:true)"}
)

var (
AnalysisCmd = []cli.Flag{ShowOutputF}
ShowOutput = "output"
Expand Down
5 changes: 4 additions & 1 deletion config/file.v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type File struct {

CLI CLIProperties
Analyze AnalyzeProperties

// Internal computed + cached properties.
modules []module.Module
}

type CLIProperties struct {
Expand Down Expand Up @@ -100,7 +103,7 @@ func readModules(file *File) ([]module.Module, error) {
var modules []module.Module
for _, config := range file.Analyze.Modules {
// Parse and validate module type.
t, err := pkg.Parse(config.Type)
t, err := pkg.ParseType(config.Type)
if err != nil {
return nil, errors.Wrapf(err, "could not parse module type %s", config.Type)
}
Expand Down
11 changes: 11 additions & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,16 @@ func Branch() string {
/**** Analysis configuration keys ****/

func Modules() []module.Module {
args := ctx.Args()
if args.Present() {
if ctx.NArg() != 1 {
}
options := ctx.StringSlice(flags.Option)
for _, a := range args {
sections := strings.Split(a, ":")
modules =
mtype := sections[0]
}
}
return file.Modules()
}
10 changes: 10 additions & 0 deletions pkg/package.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Package pkg defines a generic software package.
package pkg

import "strings"

// An ID uniquely identifies a package.
type ID struct {
// Type, Name, and Revision describe _what_ package is being identified. The
Expand All @@ -15,6 +17,14 @@ type ID struct {
Location string
}

func (id *ID) String() string {
return "id:" + escapeIDComponent(id.Type.String()) + ":" + escapeIDComponent(id.Name) + ":" + escapeIDComponent(id.Revision)
}

func escapeIDComponent(s string) string {
return strings.Replace(s, ":", "\\:", -1)
}

// An Import is a combination of a (potentially unresolved) dependency target
// and the exact resolved pkg.ID of the dependency.
type Import struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ var AllTypes = []Type{
VendoredArchives,
}

// Parse returns the canonical package type given a string key.
// ParseType returns the canonical package type given a string key.
// TODO: if we got rid of aliases, we could use `go generate` with https://github.com/alvaroloes/enumer.
func Parse(key string) (Type, error) {
func ParseType(key string) (Type, error) {
switch key {
// Ant aliases
case "ant":
Expand Down

0 comments on commit 85e221c

Please sign in to comment.