Skip to content

Commit

Permalink
Add support for jbang. Fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Sep 15, 2020
1 parent 9948ff8 commit 603e579
Show file tree
Hide file tree
Showing 16 changed files with 590 additions and 13 deletions.
9 changes: 5 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ snapcrafts:
grade: stable
confinement: strict
publish: true
summary: "Gum is a Gradle/Maven wrapper written in Go"
summary: "Gum is a Gradle/Maven/jbang wrapper written in Go"
description: |
Gum is a Gradle/Maven wrapper written in Go, inspired in https://github.com/dougborg/gdub and https://github.com/srs/gw.
Gum automatically detects if the project is Gradle or Maven based and runs the appropriate command. However in the case
Gum is a Gradle/Maven/jbang wrapper written in Go, inspired in https://github.com/dougborg/gdub and https://github.com/srs/gw.
Gum automatically detects if the project is Gradle, Maven, or jbang based and runs the appropriate command. However in the case
that Gum guesses wrong you can force a specific build tool to be used.
**Usage**
Expand All @@ -62,6 +62,7 @@ snapcrafts:
* **-gd** displays debug information
* **-gg** force Gradle build
* **-gh** displays help information
* **-gj** force jbang execution
* **-gm** force Maven build
* **-gn** executes nearest build file
* **-gq** run gm in quiet mode
Expand All @@ -79,5 +80,5 @@ brews:
name: gum-homebrew-tap
folder: Formula
homepage: "https://github.com/kordamp/gm"
description: "Gum is a Gradle/Maven wrapper written in Go"
description: "Gum is a Gradle/Maven/jbang wrapper written in Go"
skip_upload: false
15 changes: 11 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ image:https://img.shields.io/badge/donations-Patreon-orange.svg[link="https://ww

---

Gum is a link:https://gradle.org[Gradle]/link:https:maven.apache.org[Maven] wrapper written in link:https://golang.org/[Go],
inspired in link:https://github.com/dougborg/gdub[https://github.com/dougborg/gdub] and link:https://github.com/srs/gw[https://github.com/srs/gw].
Gum is a link:https://gradle.org[Gradle]/link:https:maven.apache.org[Maven]/link:https://github.com/jbangdev[jbang] wrapper written in
link:https://golang.org/[Go], inspired in link:https://github.com/dougborg/gdub[https://github.com/dougborg/gdub] and
link:https://github.com/srs/gw[https://github.com/srs/gw].

Gum automatically detects if the project is Gradle or Maven based and runs the appropriate command. However in the case that Gum guesses wrong you can force
a specific build tool to be used.
Gum automatically detects if the project is Gradle, Maven, or jbang based and runs the appropriate command. However in the case that Gum guesses wrong you can
force a specific build tool to be used.

== Usage

Expand All @@ -26,6 +27,7 @@ Gum supports the following flags
* *-gd* displays debug information
* *-gg* force Gradle build
* *-gh* displays help information
* *-gj* force jbang execution
* *-gm* force Maven build
* *-gn* executes nearest build file
* *-gq* run gm in quiet mode
Expand Down Expand Up @@ -76,6 +78,11 @@ $ gm verify

Which results in the invocation of either *gradlew* or *gradle* with the *build* goal.

.jbang

Gum will execute a given file (local or remote) if explicitly defined, otherwise scans the the current directory and executes the first file with `.java`
or `.jsh` that's found.

== Configuration

You may configure some aspects of Gum using a link:https://github.com/toml-lang/toml[TOML] based configuration file.
Expand Down
32 changes: 27 additions & 5 deletions gm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {
var args []string
gradleBuild, args := gum.GrabFlag("-gg", os.Args[1:])
mavenBuild, args := gum.GrabFlag("-gm", args)
jbangBuild, args := gum.GrabFlag("-gj", args)
quiet, args := gum.GrabFlag("-gq", args)
version, args := gum.GrabFlag("-gv", args)
help, args := gum.GrabFlag("-gh", args)
Expand All @@ -50,6 +51,7 @@ func main() {
fmt.Println(" -gd\tdisplays debug information")
fmt.Println(" -gg\tforce Gradle build")
fmt.Println(" -gh\tdisplays help information")
fmt.Println(" -gj\tforce jbang execution")
fmt.Println(" -gm\tforce Maven build")
fmt.Println(" -gn\texecutes nearest build file")
fmt.Println(" -gq\trun gm in quiet mode")
Expand All @@ -58,8 +60,19 @@ func main() {
os.Exit(0)
}

if gradleBuild && mavenBuild {
fmt.Println("You cannot define both -gg and -gm flags at the same time")
count := 0
if gradleBuild {
count = count + 1
}
if mavenBuild {
count = count + 1
}
if jbangBuild {
count = count + 1
}

if count > 1 {
fmt.Println("You cannot define -gg, -gm, or -gj flags at the same time")
os.Exit(-1)
}

Expand All @@ -69,13 +82,16 @@ func main() {
} else if mavenBuild {
cmd := gum.FindMaven(gum.NewDefaultContext(quiet, true), args)
cmd.Execute()
} else if jbangBuild {
cmd := gum.FindJbang(gum.NewDefaultContext(quiet, true), args)
cmd.Execute()
} else {
findGradleOrMaven(quiet, args)
findTool(quiet, args)
}
}

// Attempts to execute gradlew/gradle first then mvnw/mvn
func findGradleOrMaven(quiet bool, args []string) {
func findTool(quiet bool, args []string) {
context := gum.NewDefaultContext(quiet, false)

gradle := gum.FindGradle(context, args)
Expand All @@ -90,7 +106,13 @@ func findGradleOrMaven(quiet bool, args []string) {
os.Exit(0)
}

fmt.Println("Did not find a Gradle nor Maven project")
jbang := gum.FindJbang(context, args)
if jbang != nil {
jbang.Execute()
os.Exit(0)
}

fmt.Println("Did not find a Gradle, Maven, or jbang project")
os.Exit(-1)
}

Expand Down
Loading

0 comments on commit 603e579

Please sign in to comment.