Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README | LICENSE

main.go (1582B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 
      7 	"github.com/theSage21/jaypore_ci/internal/jci"
      8 )
      9 
     10 // version is set at build time via -ldflags "-X main.version=<version>".
     11 // It falls back to "dev" when built without the flag (e.g. go run).
     12 var version = "dev"
     13 
     14 func main() {
     15 	if len(os.Args) < 2 {
     16 		printUsage()
     17 		os.Exit(1)
     18 	}
     19 
     20 	cmd := os.Args[1]
     21 	args := os.Args[2:]
     22 
     23 	var err error
     24 	switch cmd {
     25 	case "run":
     26 		err = jci.Run(args)
     27 	case "web":
     28 		err = jci.Web(args)
     29 	case "push":
     30 		err = jci.Push(args)
     31 	case "pull":
     32 		err = jci.Pull(args)
     33 	case "prune":
     34 		err = jci.Prune(args)
     35 	case "cron":
     36 		err = jci.Cron(args)
     37 	case "version", "--version", "-v":
     38 		fmt.Println("git-jci version " + version)
     39 		return
     40 	case "help", "-h", "--help":
     41 		printUsage()
     42 		return
     43 	default:
     44 		fmt.Fprintf(os.Stderr, "unknown command: %s\n", cmd)
     45 		printUsage()
     46 		os.Exit(1)
     47 	}
     48 
     49 	if err != nil {
     50 		fmt.Fprintf(os.Stderr, "error: %v\n", err)
     51 		os.Exit(1)
     52 	}
     53 }
     54 
     55 func printUsage() {
     56 	fmt.Printf(`git-jci %s - Local-first CI system stored in git
     57 
     58 Usage: git jci <command> [options]
     59 
     60 Commands:
     61   run [--multi]  Run CI for the current commit and store results
     62   web            Start a web server to view CI results
     63   push           Push CI results to remote
     64   pull           Pull CI results from remote
     65   prune          Remove old CI results
     66   cron ls        List cron jobs for this repository
     67   cron sync      Sync .jci/crontab with system cron
     68   version        Print the version and exit
     69 
     70 CI results are stored in refs/jci/<commit>.
     71 With --multi, results are stored in refs/jci-runs/<commit>/<runid>.`, version)
     72 }