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

Commit

Permalink
Merge pull request #39 from everettraven/refactor/package_to_pim
Browse files Browse the repository at this point in the history
package -> pim
  • Loading branch information
everettraven authored Oct 10, 2021
2 parents c985381 + cfa13af commit dfd1a70
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 312 deletions.
8 changes: 4 additions & 4 deletions docs/docs/cli/subcommands/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ title: install

## Usage
```
packageless install [PACKAGE]
packageless install [pim]
```

Packages follow a particular format. If you specify just the package that you want installed, the latest version of the package that **packageless** has will be installed.
Packages follow a particular format. If you specify just the pim that you want installed, the latest version of the pim that **packageless** has will be installed.

You can also specify a particular version by following this format:
```
package:version
pim:version
```

To manually specify that you want the latest version you can use:
```
package:latest
pim:latest
```
however, **packageless** defaults to getting the latest version if one is not specified

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/subcommands/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ title: run

## Usage
```
packageless run [PACKAGE]
packageless run [pim]
```

When using this subcommand, **packageless** will run the package that is specified as long as it is installed. If the package is not installed the command will exit with text stating that the package specified is not installed. If you installed a specific version of a package, you will need to use the same syntax for the package for this command as well.
When using this subcommand, **packageless** will run the pim that is specified as long as it is installed. If the pim is not installed the command will exit with text stating that the pim specified is not installed. If you installed a specific version of a pim, you will need to use the same syntax for the pim for this command as well.

## Examples
:::note
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/cli/subcommands/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ title: uninstall

## Usage
```
packageless uninstall [PACKAGE]
packageless uninstall [pim]
```

Packages follow a particular format. If you specify just the package that you want uninstalled, the latest version of the package that **packageless** has will be uninstalled.
Packages follow a particular format. If you specify just the pim that you want uninstalled, the latest version of the pim that **packageless** has will be uninstalled.

You can also specify a particular version by following this format:
```
package:version
pim:version
```

To manually specify that you want the latest version you can use:
```
package:latest
pim:latest
```
however, **packageless** defaults to getting the latest version if one is not specified

Expand Down
10 changes: 5 additions & 5 deletions docs/docs/cli/subcommands/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ title: upgrade

## Usage
```
packageless upgrade [OPTIONAL: PACKAGE]
packageless upgrade [OPTIONAL: PIM]
```

This subcommand will upgrade the package with the current package information in the package list as long as the package is already installed. If a package is not specified it will upgrade all installed packages.
This subcommand will upgrade the pim with the current pim information in the pim list as long as the pim is already installed. If a pim is not specified it will upgrade all installed packages.

Packages follow a particular format. If you specify just the package that you want upgraded, the latest version of the package that **packageless** has will be upgraded.
Packages follow a particular format. If you specify just the pim that you want upgraded, the latest version of the pim that **packageless** has will be upgraded.

You can also specify a particular version by following this format:
```
package:version
pim:version
```

To manually specify that you want the latest version you can use:
```
package:latest
pim:latest
```
however, **packageless** defaults to getting the latest version if one is not specified

Expand Down
2 changes: 1 addition & 1 deletion package_list.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package "python" {
pim "python" {
base_dir="/python/"

version "latest" {
Expand Down
70 changes: 35 additions & 35 deletions subcommands/install_sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type InstallCommand struct {
//FlagSet so that we can create a custom flag
fs *flag.FlagSet

//String for the name of the package to install
//String for the name of the pim to install
name string

//Tools that can be used by the command
Expand Down Expand Up @@ -51,7 +51,7 @@ func (ic *InstallCommand) Name() string {
func (ic *InstallCommand) Init(args []string) error {

if len(args) <= 0 {
return errors.New("No package name was found. You must include the name of the package you wish to install.")
return errors.New("No pim name was found. You must include the name of the pim you wish to install.")
}

ic.name = args[0]
Expand All @@ -62,19 +62,19 @@ func (ic *InstallCommand) Init(args []string) error {
func (ic *InstallCommand) Run() error {
//Create variables to use later
var found bool
var pack utils.Package
var pim utils.PackageImage
var version utils.Version

var packName string
var packVersion string
var pimName string
var pimVersion string

if strings.Contains(ic.name, ":") {
split := strings.Split(ic.name, ":")
packName = split[0]
packVersion = split[1]
pimName = split[0]
pimVersion = split[1]
} else {
packName = ic.name
packVersion = "latest"
pimName = ic.name
pimVersion = "latest"
}

//Create the Docker client
Expand All @@ -90,33 +90,33 @@ func (ic *InstallCommand) Run() error {
}
ed := filepath.Dir(ex)

//Default location of the package list
packageList := ed + "/package_list.hcl"
//Default location of the pim list
pimList := ed + "/package_list.hcl"

packageListBody, err := ic.tools.GetHCLBody(packageList)
pimListBody, err := ic.tools.GetHCLBody(pimList)

if err != nil {
return err
}

//Parse the package list
parseOut, err := ic.tools.ParseBody(packageListBody, utils.PackageHCLUtil{})
//Parse the pim list
parseOut, err := ic.tools.ParseBody(pimListBody, utils.PimHCLUtil{})

packages := parseOut.(utils.PackageHCLUtil)
pims := parseOut.(utils.PimHCLUtil)

//Check for errors
if err != nil {
return err
}

//Look for the package we want in the package list
for _, packs := range packages.Packages {
//Look for the pim we want in the pim list
for _, pimItem := range pims.Pims {
//If we find it, set some variables and break
if packs.Name == packName {
pack = packs
if pimItem.Name == pimName {
pim = pimItem

for _, ver := range pack.Versions {
if ver.Version == packVersion {
for _, ver := range pim.Versions {
if ver.Version == pimVersion {
found = true
version = ver
break
Expand All @@ -125,36 +125,36 @@ func (ic *InstallCommand) Run() error {
}
}

//Make sure we have found the package in the package list
//Make sure we have found the pim in the pim list
if !found {
return errors.New("Could not find package " + packName + " with version '" + packVersion + "' in the package list")
return errors.New("Could not find pim " + pimName + " with version '" + pimVersion + "' in the pim list")
}

//Check if the corresponding package image is already installed
//Check if the corresponding pim image is already installed
imgExist, err := ic.tools.ImageExists(version.Image, cli)

//Check for errors
if err != nil {
return err
}

//If the image exists the package is already installed
//If the image exists the pim is already installed
if imgExist {
return errors.New("Package " + pack.Name + " is already installed")
return errors.New("pim " + pim.Name + " is already installed")
}

fmt.Println("Installing", pack.Name+":"+version.Version)
fmt.Println("Installing", pim.Name+":"+version.Version)
//Pull the image down from Docker Hub
err = ic.tools.PullImage(version.Image, cli)

if err != nil {
return err
}

fmt.Println("Creating package directories")
fmt.Println("Creating pim directories")

//Create the base directory for the package
err = ic.tools.MakeDir(ed + pack.BaseDir)
//Create the base directory for the pim
err = ic.tools.MakeDir(ed + pim.BaseDir)

if err != nil {
return err
Expand Down Expand Up @@ -209,15 +209,15 @@ func (ic *InstallCommand) Run() error {

if runtime.GOOS == "windows" {
if version.Version != "latest" {
err = ic.tools.AddAliasWin(pack.Name+":"+version.Version, ed)
err = ic.tools.AddAliasWin(pim.Name+":"+version.Version, ed)
} else {
err = ic.tools.AddAliasWin(pack.Name, ed)
err = ic.tools.AddAliasWin(pim.Name, ed)
}
} else {
if version.Version != "latest" {
err = ic.tools.AddAliasUnix(pack.Name+":"+version.Version, ed)
err = ic.tools.AddAliasUnix(pim.Name+":"+version.Version, ed)
} else {
err = ic.tools.AddAliasUnix(pack.Name, ed)
err = ic.tools.AddAliasUnix(pim.Name, ed)
}
}

Expand All @@ -226,7 +226,7 @@ func (ic *InstallCommand) Run() error {
}
}

fmt.Println(pack.Name, "successfully installed")
fmt.Println(pim.Name, "successfully installed")

return nil
}
40 changes: 20 additions & 20 deletions subcommands/install_sc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestInstallInit(t *testing.T) {
}

if ic.name != args[0] {
t.Fatal("Package Name should have been initialized as: " + args[0] + " but is: " + ic.name)
t.Fatal("pim Name should have been initialized as: " + args[0] + " but is: " + ic.name)
}
}

Expand Down Expand Up @@ -128,25 +128,25 @@ func TestInstallFlow(t *testing.T) {
var aliasCmds []string

//Fill lists
for _, pack := range mu.Pack.Packages {
for _, pim := range mu.Pim.Pims {
//Just use the first version
version := pack.Versions[0]
version := pim.Versions[0]
images = append(images, version.Image)
mkdirs = append(mkdirs, ed+pack.BaseDir)
aliasCmds = append(aliasCmds, pack.Name)
mkdirs = append(mkdirs, ed+pim.BaseDir)
aliasCmds = append(aliasCmds, pim.Name)

//Loop through volumes in the package
//Loop through volumes in the pim
for _, vol := range version.Volumes {
mkdirs = append(mkdirs, ed+vol.Path)
}

//Loop through the copies in the package
//Loop through the copies in the pim
for _, copy := range version.Copies {
copySources = append(copySources, copy.Source)
copyDests = append(copyDests, ed+copy.Dest)
}

//Just use the first package
//Just use the first pim
break
}

Expand Down Expand Up @@ -652,7 +652,7 @@ func TestInstallImageExists(t *testing.T) {

mu.ImgExist = true

expectedErr := "Package python is already installed"
expectedErr := "pim python is already installed"

mcp := &utils.MockCopyTool{}

Expand Down Expand Up @@ -699,7 +699,7 @@ func TestInstallImageExists(t *testing.T) {
func TestInstallNoPackage(t *testing.T) {
mu := utils.NewMockUtility()

expectedErr := "No package name was found. You must include the name of the package you wish to install."
expectedErr := "No pim name was found. You must include the name of the pim you wish to install."

mcp := &utils.MockCopyTool{}

Expand All @@ -725,7 +725,7 @@ func TestInstallNoPackage(t *testing.T) {
}
}

//Test the install subcommand if the passed in package does not exist
//Test the install subcommand if the passed in pim does not exist
func TestInstallNonExistPackage(t *testing.T) {
mu := utils.NewMockUtility()

Expand All @@ -742,7 +742,7 @@ func TestInstallNonExistPackage(t *testing.T) {

args := []string{"nonexistent"}

expectedErr := "Could not find package nonexistent with version 'latest' in the package list"
expectedErr := "Could not find pim nonexistent with version 'latest' in the pim list"

err := ic.Init(args)

Expand Down Expand Up @@ -838,24 +838,24 @@ func TestInstallAliasFalse(t *testing.T) {
var mkdirs []string

//Fill lists
for _, pack := range mu.Pack.Packages {
for _, pim := range mu.Pim.Pims {
//Just use the first version
version := pack.Versions[0]
version := pim.Versions[0]
images = append(images, version.Image)
mkdirs = append(mkdirs, ed+pack.BaseDir)
mkdirs = append(mkdirs, ed+pim.BaseDir)

//Loop through volumes in the package
//Loop through volumes in the pim
for _, vol := range version.Volumes {
mkdirs = append(mkdirs, ed+vol.Path)
}

//Loop through the copies in the package
//Loop through the copies in the pim
for _, copy := range version.Copies {
copySources = append(copySources, copy.Source)
copyDests = append(copyDests, ed+copy.Dest)
}

//Just use the first package
//Just use the first pim
break
}

Expand Down Expand Up @@ -896,7 +896,7 @@ func TestInstallAliasFalse(t *testing.T) {

}

//Test the install function with a nonexistent package version
//Test the install function with a nonexistent pim version
func TestInstallNonExistVersion(t *testing.T) {
mu := utils.NewMockUtility()

Expand All @@ -913,7 +913,7 @@ func TestInstallNonExistVersion(t *testing.T) {

args := []string{"python:idontexist"}

expectedErr := "Could not find package python with version 'idontexist' in the package list"
expectedErr := "Could not find pim python with version 'idontexist' in the pim list"

err := ic.Init(args)

Expand Down
Loading

0 comments on commit dfd1a70

Please sign in to comment.