Skip to content

Commit

Permalink
Handle relative or absolute program paths
Browse files Browse the repository at this point in the history
Use filepath.Abs to create ProgramPath which automatically handles relative
or absolute paths instead of joining path elements manually.
  • Loading branch information
sanderssj committed Jul 27, 2021
1 parent 3de88b2 commit 1cf057d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions cmd/cmd_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"time"
Expand Down Expand Up @@ -51,8 +49,11 @@ func deployCommandHandler(cmd *cobra.Command, args []string) {

program := args[0]
c.Program = program
curdir, _ := os.Getwd()
c.ProgramPath = path.Join(curdir, c.Program)
var err error
c.ProgramPath, err = filepath.Abs(c.Program)
if err != nil {
exitWithError(err.Error())
}
checkProgramExists(c.Program)

if len(c.Args) == 0 {
Expand All @@ -62,7 +63,7 @@ func deployCommandHandler(cmd *cobra.Command, args []string) {
}

mergeConfigContainer := NewMergeConfigContainer(configFlags, globalFlags, nightlyFlags, nanosVersionFlags, buildImageFlags, providerFlags, pkgFlags, createInstanceFlags)
err := mergeConfigContainer.Merge(c)
err = mergeConfigContainer.Merge(c)
if err != nil {
exitWithError(err.Error())
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/cmd_run.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cmd

import (
"os"
"path"
"path/filepath"

"github.com/nanovms/ops/lepton"
api "github.com/nanovms/ops/lepton"
Expand Down Expand Up @@ -35,8 +34,11 @@ func runCommandHandler(cmd *cobra.Command, args []string) {

program := args[0]
c.Program = program
curdir, _ := os.Getwd()
c.ProgramPath = path.Join(curdir, c.Program)
var err error
c.ProgramPath, err = filepath.Abs(c.Program)
if err != nil {
exitWithError(err.Error())
}
checkProgramExists(c.Program)

flags := cmd.Flags()
Expand All @@ -49,7 +51,7 @@ func runCommandHandler(cmd *cobra.Command, args []string) {
runLocalInstanceFlags := NewRunLocalInstanceCommandFlags(flags)

mergeContainer := NewMergeConfigContainer(configFlags, globalFlags, nightlyFlags, nanosVersionFlags, buildImageFlags, runLocalInstanceFlags)
err := mergeContainer.Merge(c)
err = mergeContainer.Merge(c)
if err != nil {
exitWithError(err.Error())
}
Expand Down

0 comments on commit 1cf057d

Please sign in to comment.