-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/dpastoor/qvm/internal/config" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type initCmd struct { | ||
cmd *cobra.Command | ||
opts initOpts | ||
} | ||
|
||
type initOpts struct { | ||
} | ||
|
||
func newInit(initOpts initOpts) error { | ||
activeDir := config.GetPathToActiveBinDir() | ||
activeIndex := strings.Index(os.Getenv("PATH"), activeDir) | ||
if activeIndex == -1 { | ||
fmt.Println("please add the active bin directory to your path") | ||
fmt.Println(`you can dynamically query the active bin directory by running: "qvm path active" | ||
if you would like to script this, you can add the following to your ~/.bashrc or ~/.zshrc: | ||
export PATH="$(qvm path active):$PATH") | ||
`) | ||
|
||
} else { | ||
fmt.Println("already detect qvm active directory on your path - you're good to go!") | ||
} | ||
return nil | ||
} | ||
|
||
func setInitOpts(initOpts *initOpts) { | ||
|
||
} | ||
|
||
func (opts *initOpts) Validate() error { | ||
return nil | ||
} | ||
|
||
func newInitCmd() *initCmd { | ||
root := &initCmd{opts: initOpts{}} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "init", | ||
Short: "initialize qvm", | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
setInitOpts(&root.opts) | ||
if err := root.opts.Validate(); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
//TODO: Add your logic to gather config to pass code here | ||
log.WithField("opts", fmt.Sprintf("%+v", root.opts)).Trace("init-opts") | ||
if err := newInit(root.opts); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
root.cmd = cmd | ||
return root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/dpastoor/qvm/internal/config" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type pathAddCmd struct { | ||
cmd *cobra.Command | ||
opts pathAddOpts | ||
} | ||
|
||
type pathAddOpts struct { | ||
} | ||
|
||
func newPathAdd(pathAddOpts pathAddOpts) error { | ||
path := os.Getenv("PATH") | ||
pathToAdd := config.GetPathToActiveBinDir() | ||
activeIndex := strings.Index(path, pathToAdd) | ||
if activeIndex == -1 { | ||
path = fmt.Sprintf("%s:%s", pathToAdd, path) | ||
} | ||
fmt.Println(path) | ||
return nil | ||
} | ||
|
||
func setPathAddOpts(pathAddOpts *pathAddOpts) { | ||
|
||
} | ||
|
||
func (opts *pathAddOpts) Validate() error { | ||
return nil | ||
} | ||
|
||
func newPathAddCmd() *pathAddCmd { | ||
root := &pathAddCmd{opts: pathAddOpts{}} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "add", | ||
Short: "add qvm directories to the path, if they don't exist", | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
setPathAddOpts(&root.opts) | ||
if err := root.opts.Validate(); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
//TODO: Add your logic to gather config to pass code here | ||
log.WithField("opts", fmt.Sprintf("%+v", root.opts)).Trace("pathAdd-opts") | ||
if err := newPathAdd(root.opts); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
root.cmd = cmd | ||
return root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters