Skip to content

Commit

Permalink
support build version
Browse files Browse the repository at this point in the history
  • Loading branch information
liujianping committed May 8, 2019
1 parent fbc8e5f commit a539d29
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,21 @@ make your short-term command as a long-term job

Brew install

````
````bash
$: brew tap liujianping/tap && brew install job
````

OR go source install
OR

````
````bash
$: git clone https://github.com/liujianping/job.git
$: cd job
$: go build -mod vendor
````

OR without go module enable,

````
$: go get -u github.com/liujianping/job
````

## Usage

````shell
````bash

$: job -h
Job, make your short-term command as a long-term job
Expand Down Expand Up @@ -72,7 +65,7 @@ Flags:

#### ** Output Job **

````
````bash
$: job -n 10 -i 500ms -T 3s -o -- curl https://www.baidu.com
Job:
name: ""
Expand Down Expand Up @@ -161,7 +154,7 @@ Job:

#### ** Local Report **

````
````bash
$: job -n 10 -i 500ms -c 5 -R -- echo hello

Uptime: 5.1037 secs
Expand Down
21 changes: 21 additions & 0 deletions build/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package build

import "fmt"

var (
version = "dev"
commit = "none"
date = "unknown"
)

//Print version
func Print() {
fmt.Printf("%v, commit %v, built at %v\n", version, commit, date)
}

//Info build info
func Info(v, m, d string) {
version = v
commit = m
date = d
}
9 changes: 8 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/liujianping/job/config"
"github.com/liujianping/job/exec"
"github.com/liujianping/job/build"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -28,10 +29,16 @@ func CheckErr(err error) {
}

func Main(cmd *cobra.Command, args []string) {
if viper.GetBool("version") {
build.Print()
os.Exit(0)
}

if len(viper.GetString("config")) == 0 && len(args) == 0 {
cmd.Usage()
cmd.Help()
os.Exit(0)
}

jds := []*config.JD{}
if len(viper.GetString("config")) > 0 {
cfs, err := config.ParseJDs(viper.GetString("config"))
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func init() {
rootCmd.Flags().BoolP("guarantee", "G", false, "job guarantee mode enable ?")
rootCmd.Flags().BoolP("report", "R", false, "job report enable ?")
rootCmd.Flags().StringP("report-push-gateway", "P", "", "job report to prometheus push gateway address")
rootCmd.Flags().DurationP("report-push-interval", "I", 0*time.Second, "job report to prometheus push gateway interval")
rootCmd.Flags().BoolP("output", "o", false, "job yaml config output enable ?")
rootCmd.Flags().BoolP("verbose", "V", false, "job verbose log enable ?")
rootCmd.Flags().BoolP("version", "v", false, "job version")

// TODO support Distributed-Job
// rootCmd.Flags().StringP("host", "H", "", "dispatch JOB to the Host")
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@

package main

import "github.com/liujianping/job/cmd"
import (
"github.com/liujianping/job/build"
"github.com/liujianping/job/cmd"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

//go:generate protoc pb/job.proto --go_out=${GOPATH}/src
func main() {
build.Info(version, commit, date)
cmd.Execute()
}

0 comments on commit a539d29

Please sign in to comment.