-
Notifications
You must be signed in to change notification settings - Fork 177
Extract: Detect app in cwd and subdirs. #51
Conversation
packager/extract.go
Outdated
} | ||
appname = path.Join(cwd, hit) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be put in a fonction maybe?
packager/extract.go
Outdated
for _, c := range content { | ||
if strings.HasSuffix(c.Name(), constants.AppExtension) { | ||
if hit != "" { | ||
return "", nil, fmt.Errorf("multiple apps found in current directory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we should probably suggest to the user how to proceed (e.g. specify the app on the command line)?
app := "" | ||
if len(args) > 0 { | ||
app = args[0] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that fail or is it just in case? Because I don't believe it is possible for args[0] not to contain the application name, that is if cobra args are actually os.Args of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right this is actually the first arg of the command, nothing to do with the application name… Never mind…
@mat007 split in a subfunction and improved error message |
if len(args) > 0 { | ||
app = args[0] | ||
} | ||
err := packager.Unpack(app, unpackOutputDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nb: this could be factorized, maybe something like
err := packager.Unpack(firstArg(args), unpackOutpuDir)
and
func firstArg(args []string) string {
if len(args) > 0 {
return args[0]
}
return ""
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but will be in a followup though as it conflicts with an other PR in my stack.
packager/extract.go
Outdated
@@ -14,9 +18,45 @@ var ( | |||
noop = func() {} | |||
) | |||
|
|||
// FindApp looks for an app in CWD or subdirs | |||
func FindApp() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually need to be exported, does it? So findApp
?
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple nits but otherwise LGTM
func Extract(appname string) (string, func(), error) { | ||
if appname == "" { | ||
var err error | ||
appname, err = findApp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: think you can do:
var err error
if appname, err = findApp(); err != nil {
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same further down:
if err = extract(appname, tempDir); err != nil {
...
Signed-off-by: Matthieu Nottale matthieu.nottale@docker.com