<commit_before>package main

import (
	"archive/tar"
	"compress/gzip"
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"os"
	"os/exec"
	"path/filepath"
	"runtime/debug"
	"strings"
	"sync"
	"time"

	"github.com/cheggaaa/pb"
	"golang.org/x/crypto/ssh"
	"golang.org/x/crypto/ssh/agent"
)

// TODOs
// 	rollback
// 	snapshot

// TODO: put everything inside app path
// local
// 	pwd/tmp/harp
// 	pwd/migration
//
// server
// 	$GOPATH/bin
// 	$GOPATH/src
// 	$GOPATH/pid
// 	$GOPATH/log
// 	$GOPATH/migration/$APP
// 	$GOPATH/script

// use cases 1: in pwd: go build -> upload -> run

type Config struct {
	GOOS, GOARCH string

	// TODO
	Rollback int

	// TODO: multiple instances support
	// TODO: multiple apps support
	App App

	// TODO: migration and flag support (-after and -before)
	Hooks struct {
		Deploy struct {
			Before, After string
		}
	}

	Servers map[string][]Server
}

type App struct {
	Name       string
	ImportPath string
	Files      []string
	Args       []string

	BuildCmd    string
	BuildScript string
}

type Server struct {
	Env    []string // key=value
	GoPath string
	LogDir string
	PIDDir string

	User string
	Host string
	Port string

	client *ssh.Client
}

var (
	verbose   bool
	debugf    bool
	noBuild   bool
	noUpload  bool
	noDeploy  bool
	noFiles   bool
	toTailLog bool
	script    string
	migration string

	// TODO: can specify a single server, instead of the whole server set
	serverSet  string
	serverSets []string
	help       bool

	cfg    Config
	GoPath = os.Getenv("GOPATH")
)

func main() {
	var configPath string
	flag.StringVar(&configPath, "c", "harp.json", "config file path")
	flag.BoolVar(&debugf, "debug", false, "print debug info")
	flag.BoolVar(&verbose, "v", false, "verbose")
	flag.BoolVar(&noBuild, "nb", false, "no build")
	flag.BoolVar(&noUpload, "nu", false, "no upload")
	flag.BoolVar(&noDeploy, "nd", false, "no deploy")
	flag.BoolVar(&noFiles, "nf", false, "no files")
	flag.BoolVar(&help, "help", false, "print helps")
	flag.BoolVar(&help, "h", false, "print helps")
	flag.BoolVar(&toTailLog, "log", false, "tail log after deploy")
	flag.StringVar(&script, "scripts", "", "scripts to build and run on server")
	flag.StringVar(&serverSet, "s", "", "specify server sets to deploy, multiple sets are split by comma")
	flag.StringVar(&serverSet, "server-set", "", "specify server sets to deploy, multiple sets are split by comma")
	flag.StringVar(&migration, "m", "", "specify migrations to run on server, multiple migrations are split by comma")
	// flag.StringVar(&server, "server", "", "specify servers to deploy, multiple servers are split by comma")
	flag.Parse()

	args := flag.Args()<commit_msg>add version flag<commit_after>package main

import (
	"archive/tar"
	"compress/gzip"
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"os"
	"os/exec"
	"path/filepath"
	"runtime/debug"
	"strings"
	"sync"
	"time"

	"github.com/cheggaaa/pb"
	"golang.org/x/crypto/ssh"
	"golang.org/x/crypto/ssh/agent"
)

// TODOs
// 	rollback
// 	snapshot

// TODO: put everything inside app path
// local
// 	pwd/tmp/harp
// 	pwd/migration
//
// server
// 	$GOPATH/bin
// 	$GOPATH/src
// 	$GOPATH/pid
// 	$GOPATH/log
// 	$GOPATH/migration/$APP
// 	$GOPATH/script

// use cases 1: in pwd: go build -> upload -> run

type Config struct {
	GOOS, GOARCH string

	// TODO
	Rollback int

	// TODO: multiple instances support
	// TODO: multiple apps support
	App App

	// TODO: migration and flag support (-after and -before)
	Hooks struct {
		Deploy struct {
			Before, After string
		}
	}

	Servers map[string][]Server
}

type App struct {
	Name       string
	ImportPath string
	Files      []string
	Args       []string

	BuildCmd    string
	BuildScript string
}

type Server struct {
	Env    []string // key=value
	GoPath string
	LogDir string
	PIDDir string

	User string
	Host string
	Port string

	client *ssh.Client
}

var (
	verbose   bool
	debugf    bool
	noBuild   bool
	noUpload  bool
	noDeploy  bool
	noFiles   bool
	toTailLog bool
	script    string
	migration string

	// TODO: can specify a single server, instead of the whole server set
	serverSet  string
	serverSets []string
	help       bool
	versionf   bool

	cfg    Config
	GoPath = os.Getenv("GOPATH")
)

func main() {
	var configPath string
	flag.StringVar(&configPath, "c", "harp.json", "config file path")
	flag.BoolVar(&debugf, "debug", false, "print debug info")
	// flag.BoolVar(&verbose, "v", false, "verbose")

	flag.BoolVar(&noBuild, "nb", false, "no build")
	flag.BoolVar(&noUpload, "nu", false, "no upload")
	flag.BoolVar(&noDeploy, "nd", false, "no deploy")
	flag.BoolVar(&noFiles, "nf", false, "no files")

	flag.BoolVar(&toTailLog, "log", false, "tail log after deploy")

	flag.BoolVar(&help, "help", false, "print helps")
	flag.BoolVar(&help, "h", false, "print helps")
	flag.BoolVar(&versionf, "v", false, "print version num")
	flag.BoolVar(&versionf, "version", false, "print version num")

	flag.StringVar(&script, "scripts", "", "scripts to build and run on server")

	flag.StringVar(&serverSet, "s", "", "specify server sets to deploy, multiple sets are split by comma")
	flag.StringVar(&serverSet, "server-set", "", "specify server sets to deploy, multiple sets are split by comma")

	flag.StringVar(&migration, "m", "", "specify migrations to run on server, multiple migrations are split by comma")
	// flag.StringVar(&server, "server", "", "specify servers to deploy, multiple servers are split by comma")
	flag.Parse()

	if versionf {
		fmt.Println(version)
		return
	}

	args := flag.Args()
{'fraction_non_alphanumeric': 0.13855855855855856, 'fraction_numerical': 0.00036036036036036037, 'mean_word_length': 3.524042379788101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2569186', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1978, 'n_words': 587}