Skip to content

Commit

Permalink
Merge pull request #26 from deadcheat/feature/issue-24-and-25
Browse files Browse the repository at this point in the history
Feature/issue 24 and 25
  • Loading branch information
deadcheat committed Jan 24, 2019
2 parents 6afee74 + 57a3efe commit 3056a47
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -47,7 +47,7 @@ USAGE:
goblet [global options] command [command options] [arguments...]
VERSION:
1.2.0
1.2.2
COMMANDS:
help, h Shows a list of commands or help for one command
Expand Down
2 changes: 1 addition & 1 deletion cmd/goblet/main.go
Expand Up @@ -19,7 +19,7 @@ func main() {

app.Name = "goblet"
app.Usage = "make a binary contain some assets"
app.Version = "1.2.1"
app.Version = "1.2.2"

app.Flags = values.FlagDefs
// mount presenter
Expand Down
11 changes: 11 additions & 0 deletions generator/presenter/file/presenter.go
Expand Up @@ -14,6 +14,7 @@ import (
"sort"
"strings"

"github.com/deadcheat/goblet"
"github.com/deadcheat/goblet/generator"
pt "github.com/deadcheat/goblet/generator/presenter/file/template"
"github.com/deadcheat/goblet/generator/values"
Expand Down Expand Up @@ -77,6 +78,7 @@ func (p *Presenter) action(c *cli.Context) error {
DirMap: e.DirMap,
FileMap: e.FileMap,
Paths: e.Paths,
HasFileData: hasAnyData(e.FileMap),
}
targetPaths := paths
var writer io.Writer = os.Stdout
Expand Down Expand Up @@ -119,6 +121,15 @@ func (p *Presenter) action(c *cli.Context) error {
return nil
}

func hasAnyData(m map[string]*goblet.File) bool {
for _, v := range m {
if len(v.Data ) != 0 {
return true
}
}
return false
}

func executedCommand(c *cli.Context, argPaths []string) string {
var buf bytes.Buffer
// write command itself
Expand Down
2 changes: 1 addition & 1 deletion generator/presenter/file/presenter_test.go
Expand Up @@ -155,7 +155,7 @@ func TestActionSuccessWithStdout(t *testing.T) {
// stdout pattern
ctx := cli.NewContext(a, set, nil)
if err := p.action(ctx); err != nil {
t.Error("Mount should not return any error: ", err)
t.Error("action should not return any error: ", err)
}
}

Expand Down
8 changes: 5 additions & 3 deletions generator/presenter/file/template/template.go
Expand Up @@ -11,6 +11,7 @@ type Assets struct {
DirMap map[string][]string
FileMap map[string]*goblet.File
Paths []string
HasFileData bool
}

// AssetFileTemplate template for asset file
Expand All @@ -36,15 +37,16 @@ var {{ $VarName }} = goblet.NewFS(
},
map[string]*goblet.File {
{{- range $p := .Paths }}{{ with (index $FileMap $p)}}
"{{$p}}": goblet.NewFile("{{$p}}", {{if .IsDir }}nil{{ else }}[]byte(_{{ $VarName }}{{ sha1 $p }}){{ end }}, {{ printf "%#v" .FileMode }}, time.Unix({{ .ModifiedAt.Unix }}, {{ .ModifiedAt.UnixNano }})),{{ end }}
"{{$p}}": goblet.NewFile("{{$p}}", {{if .IsDir }}nil{{ else if eq (len .Data) 0 }}[]byte{}{{ else }}_{{ $VarName }}{{ sha1 $p }}{{ end }}, {{ printf "%#v" .FileMode }}, time.Unix({{ .ModifiedAt.Unix }}, {{ .ModifiedAt.UnixNano }})),{{ end }}
{{- end }}
},
)
{{ if .HasFileData }}
// binary data
var (
{{- range $p := .Paths }}{{ with (index $FileMap $p) }}
{{if not .IsDir }}_{{ $VarName }}{{ sha1 $p}} = {{ printData .Data }}{{ end }}{{ end }}
{{if and (not .IsDir) ( ne (len .Data) 0) }}_{{ $VarName }}{{ sha1 $p}} = []byte({{ printData .Data }}){{ end }}{{ end }}
{{- end }}
)
{{ end }}
`
4 changes: 2 additions & 2 deletions generator/usecase/file/usecase.go
Expand Up @@ -50,7 +50,7 @@ func (u *UseCase) LoadFiles(paths []string, option generator.OptionFlagEntity) (
path := paths[i]
if err := u.addFile(path); err != nil {
if err == ErrFileIsNotMatchExpression {
log.Printf("path %s is not matched pattern given in 'expression(e)' flag", path)
log.Printf("%s is excluded because it is not matched with specified condition", path)
continue
}
return nil, err
Expand Down Expand Up @@ -105,7 +105,7 @@ func (u *UseCase) addFile(path string) (err error) {
err = u.addFile(childPath)
if err != nil {
if err == ErrFileIsNotMatchExpression {
log.Printf("path %s is not matched pattern given in 'expression(e)' flag", path)
log.Printf("%s is excluded because it is not matched with specified condition", childPath)
continue
}
return err
Expand Down

0 comments on commit 3056a47

Please sign in to comment.