Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

make setting alias optional #28

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
base_dir="./"
start_port=3000
port_increment=1
alias=true
32 changes: 29 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"path/filepath"

"github.com/everettraven/packageless/subcommands"
"github.com/everettraven/packageless/utils"
Expand All @@ -25,12 +26,37 @@ func wrappedMain() (int, error) {
//Create the copier for the subcommands
cp := &utils.CopyTool{}

//Create a variable for the executable directory
ex, err := os.Executable()
if err != nil {
return 1, err
}
ed := filepath.Dir(ex)

//Config file location
configLoc := ed + "/config.hcl"

configBody, err := util.GetHCLBody(configLoc)

if err != nil {
return 1, err
}

//Parse the config file
parseOut, err := util.ParseBody(configBody, utils.Config{})

if err != nil {
return 1, err
}

config := parseOut.(utils.Config)

//Create the list of subcommands
scmds := []subcommands.Runner{
subcommands.NewInstallCommand(util, cp),
subcommands.NewUninstallCommand(util),
subcommands.NewInstallCommand(util, cp, config),
subcommands.NewUninstallCommand(util, config),
subcommands.NewUpgradeCommand(util, cp),
subcommands.NewRunCommand(util),
subcommands.NewRunCommand(util, config),
}

//Run the subcommands
Expand Down
31 changes: 18 additions & 13 deletions subcommands/install_sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ type InstallCommand struct {
tools utils.Tools

cp utils.Copier

config utils.Config
}

//Instantiation method for a new InstallCommand
func NewInstallCommand(tools utils.Tools, cp utils.Copier) *InstallCommand {
func NewInstallCommand(tools utils.Tools, cp utils.Copier, config utils.Config) *InstallCommand {
//Create a new InstallCommand and set the FlagSet
ic := &InstallCommand{
fs: flag.NewFlagSet("install", flag.ContinueOnError),
tools: tools,
cp: cp,
fs: flag.NewFlagSet("install", flag.ContinueOnError),
tools: tools,
cp: cp,
config: config,
}

return ic
Expand Down Expand Up @@ -180,17 +183,19 @@ func (ic *InstallCommand) Run() error {

}

//Set the alias for the command
fmt.Println("Setting Alias")
if ic.config.Alias {
//Set the alias for the command
fmt.Println("Setting Alias")

if runtime.GOOS == "windows" {
err = ic.tools.AddAliasWin(pack.Name, ed)
} else {
err = ic.tools.AddAliasUnix(pack.Name, ed)
}
if runtime.GOOS == "windows" {
err = ic.tools.AddAliasWin(pack.Name, ed)
} else {
err = ic.tools.AddAliasUnix(pack.Name, ed)
}

if err != nil {
return err
if err != nil {
return err
}
}

fmt.Println(pack.Name, "successfully installed")
Expand Down
Loading