-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mcred/feature/distinct-add-install-commands
Feature/distinct add install commands
- Loading branch information
Showing
17 changed files
with
394 additions
and
186 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
bin | ||
.idea | ||
temp_packages.json | ||
temp_packages.json | ||
liquibase_modules | ||
liquibase.json |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.0.2 | ||
0.0.3 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.2 | ||
0.0.3 |
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,73 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"package-manager/internal/app" | ||
"package-manager/internal/app/dependencies" | ||
"package-manager/internal/app/errors" | ||
"package-manager/internal/app/packages" | ||
"strings" | ||
) | ||
|
||
// addCmd represents the add command | ||
var addCmd = &cobra.Command{ | ||
Use: "add [PACKAGE]...", | ||
Short: "Add Packages", | ||
Args: cobra.ArbitraryArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
// Set global vs local classpath | ||
app.SetClasspath(global, globalpath, globalpathFiles) | ||
|
||
d := dependencies.Dependencies{} | ||
|
||
for _, name := range args { | ||
var p packages.Package | ||
var v packages.Version | ||
if strings.Contains(name, "@") { | ||
p = packs.GetByName(strings.Split(name, "@")[0]) | ||
v = p.GetVersion(strings.Split(name, "@")[1]) | ||
if v.Tag == "" { | ||
errors.Exit("Version '"+strings.Split(name, "@")[1]+"' not available.", 1) | ||
} | ||
} else { | ||
p = packs.GetByName(name) | ||
v = p.GetLatestVersion() | ||
} | ||
if p.Name == "" { | ||
errors.Exit("Package '"+name+"' not found.", 1) | ||
} | ||
if v.InClassPath(app.ClasspathFiles) { | ||
errors.Exit(name+" is already installed.", 1) | ||
} | ||
if !v.PathIsHttp() { | ||
v.CopyToClassPath(app.Classpath) | ||
} else { | ||
v.DownloadToClassPath(app.Classpath) | ||
} | ||
fmt.Println(v.GetFilename() + " successfully installed in classpath.") | ||
d.Dependencies = append(d.Dependencies, dependencies.Dependency{p.Name: v.Tag}) | ||
} | ||
|
||
if !global { | ||
//Add package to local manifest | ||
if !d.FileExists() { | ||
d.CreateFile() | ||
} | ||
d.Write() | ||
|
||
// Output helper for JAVA_OPTS | ||
p := "-cp liquibase_modules/*:" + globalpath + "*:" + liquibaseHome + "liquibase.jar" | ||
fmt.Println() | ||
fmt.Println("---------- IMPORTANT ----------") | ||
fmt.Println("Add the following JAVA_OPTS to your CLI:") | ||
fmt.Println("export JAVA_OPTS=\"" + p + "\"") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(addCmd) | ||
addCmd.Flags().BoolVarP(&global, "global", "g", false, "add package globally") | ||
} |
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
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,56 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"package-manager/internal/app" | ||
"package-manager/internal/app/dependencies" | ||
"package-manager/internal/app/errors" | ||
) | ||
|
||
// removeCmd represents the install command | ||
var removeCmd = &cobra.Command{ | ||
Use: "remove [PACKAGE]...", | ||
Short: "Removes Package", | ||
Aliases: []string{"rm"}, | ||
Args: cobra.ArbitraryArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
// Set global vs local classpath | ||
app.SetClasspath(global, globalpath, globalpathFiles) | ||
|
||
d := dependencies.Dependencies{} | ||
if !global { | ||
d.Read() | ||
} | ||
|
||
// Remove Each Package | ||
for _, name := range args { | ||
p := packs.GetByName(name) | ||
v := p.GetInstalledVersion(app.ClasspathFiles) | ||
if p.Name == "" { | ||
errors.Exit("Package '" + name + "' not found.", 1) | ||
} | ||
if !v.InClassPath(app.ClasspathFiles) { | ||
errors.Exit(name + " is not installed.", 1) | ||
} | ||
err := os.Remove(app.Classpath + v.GetFilename()) | ||
if err != nil { | ||
errors.Exit("Unable to delete " + v.GetFilename() + " from classpath.", 1) | ||
} | ||
fmt.Println(v.GetFilename() + " successfully uninstalled from classpath.") | ||
if !global{ | ||
d.Remove(p.Name) | ||
} | ||
} | ||
if !global{ | ||
d.Write() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(removeCmd) | ||
removeCmd.Flags().BoolVarP(&global, "global", "g", false, "remove package globally") | ||
} |
Oops, something went wrong.