mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Update Iris tool to v.0.0.4 - Install dir now is based on $GOPATH/src
This commit is contained in:
parent
26f13cf5bf
commit
0e05c68876
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
This package is the command line tool for [../](https://github.com/kataras/iris).
|
This package is the command line tool for [../](https://github.com/kataras/iris).
|
||||||
|
|
||||||
|
[!Iris help screen](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen.png)](https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/iris_cli_screen.png)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
Current version: 0.0.3
|
Current version: 0.0.4
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
go get -u github.com/kataras/iris/iris
|
go get -u github.com/kataras/iris/iris
|
||||||
|
@ -28,16 +29,16 @@ $ iris [command] [-flags]
|
||||||
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
iris create -t basic -d ./
|
iris create -t basic -d myprojects/iris1
|
||||||
```
|
```
|
||||||
|
|
||||||
Will create the [basic](https://github.com/iris-contrib/iris-command-assets/tree/master/basic) sample package to the current working directory and run the app.
|
Will create the [basic](https://github.com/iris-contrib/iris-command-assets/tree/master/basic) sample package to the `$GOPATH/src/myprojects/iris1` directory and run the app.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
iris create -t static -d ./
|
iris create -t static -d myprojects/iris1
|
||||||
```
|
```
|
||||||
|
|
||||||
Will create the [static](https://github.com/iris-contrib/iris-command-assets/tree/master/static) sample package to the current working directory and run the app.
|
Will create the [static](https://github.com/iris-contrib/iris-command-assets/tree/master/static) sample package to the `$GOPATH/src/myprojects/iris1` directory and run the app.
|
||||||
|
|
||||||
|
|
||||||
The default
|
The default
|
||||||
|
@ -46,13 +47,13 @@ The default
|
||||||
iris create
|
iris create
|
||||||
```
|
```
|
||||||
|
|
||||||
Will create the basic sample package to the current working directory and run the app.
|
Will create the basic sample package to `$GOPATH/src/myiris` directory and run the app.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
iris create -d C:\Users\kataras\Desktop\test1
|
iris create -d myproject
|
||||||
```
|
```
|
||||||
|
|
||||||
Will create the basic sample package to the C:\Users\kataras\Desktop\test1 folder and run the app.
|
Will create the basic sample package to the `$GOPATH/src/myproject` folder and run the app.
|
||||||
|
|
||||||
|
|
||||||
## Version
|
## Version
|
||||||
|
|
47
iris/main.go
47
iris/main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
@ -30,13 +31,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app = cli.NewApp("iris", "Command line tool for Iris web framework", "0.0.3")
|
app = cli.NewApp("iris", "Command line tool for Iris web framework", "0.0.4")
|
||||||
app.Command(cli.Command("version", "\t prints your iris version").Action(func(cli.Flags) error { app.Printf("%s", iris.Version); return nil }))
|
app.Command(cli.Command("version", "\t prints your iris version").Action(func(cli.Flags) error { app.Printf("%s", iris.Version); return nil }))
|
||||||
|
|
||||||
createCmd := cli.Command("create", "create a project to a given directory").
|
createCmd := cli.Command("create", "create a project to a given directory").
|
||||||
Flag("offline", false, "set to true to disable the packages download on each create command").
|
Flag("offline", false, "set to true to disable the packages download on each create command").
|
||||||
Flag("dir", "./", "creates an iris starter kit to the current directory").
|
Flag("dir", "myiris", "$GOPATH/src/$dir the directory to install the sample package").
|
||||||
Flag("type", "basic", "creates the project based on the -t package. Currently, available types are 'basic' & 'static'").
|
Flag("type", "basic", "creates a project based on the -t package. Currently, available types are 'basic' & 'static'").
|
||||||
Action(create)
|
Action(create)
|
||||||
|
|
||||||
app.Command(createCmd)
|
app.Command(createCmd)
|
||||||
|
@ -54,13 +55,14 @@ func create(flags cli.Flags) (err error) {
|
||||||
|
|
||||||
targetDir := flags.String("dir")
|
targetDir := flags.String("dir")
|
||||||
|
|
||||||
|
// remove first and last / if any
|
||||||
if strings.HasPrefix(targetDir, "./") || strings.HasPrefix(targetDir, "."+utils.PathSeparator) {
|
if strings.HasPrefix(targetDir, "./") || strings.HasPrefix(targetDir, "."+utils.PathSeparator) {
|
||||||
currentWdir, err := os.Getwd()
|
targetDir = targetDir[2:]
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
targetDir = currentWdir + utils.PathSeparator + targetDir[2:]
|
|
||||||
}
|
}
|
||||||
|
if targetDir[len(targetDir)-1] == '/' {
|
||||||
|
targetDir = targetDir[0 : len(targetDir)-1]
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
createPackage(flags.String("type"), targetDir)
|
createPackage(flags.String("type"), targetDir)
|
||||||
return
|
return
|
||||||
|
@ -90,23 +92,42 @@ func downloadPackages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createPackage(packageName string, targetDir string) error {
|
func createPackage(packageName string, targetDir string) error {
|
||||||
|
installTo := os.Getenv("GOPATH") + utils.PathSeparator + "src" + utils.PathSeparator + targetDir
|
||||||
|
|
||||||
packageDir := packagesInstallDir + utils.PathSeparator + packageName
|
packageDir := packagesInstallDir + utils.PathSeparator + packageName
|
||||||
err := utils.CopyDir(packageDir, targetDir)
|
err := utils.CopyDir(packageDir, installTo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Printf("\nProblem while copying the %s package to the %s. Trace: %s", packageName, targetDir, err.Error())
|
app.Printf("\nProblem while copying the %s package to the %s. Trace: %s", packageName, installTo, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now replace main.go's 'github.com/iris-contrib/iris-command-assets/basic/' with targetDir
|
||||||
|
// hardcode all that, we don't have anything special and neither will do
|
||||||
|
targetDir = strings.Replace(targetDir, "\\", "/", -1) // for any case
|
||||||
|
mainFile := installTo + utils.PathSeparator + "backend" + utils.PathSeparator + "main.go"
|
||||||
|
|
||||||
|
input, err := ioutil.ReadFile(mainFile)
|
||||||
|
if err != nil {
|
||||||
|
app.Printf("Error while preparing main file: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
output := strings.Replace(string(input), "github.com/iris-contrib/iris-command-assets/"+packageName+"/", targetDir+"/", -1)
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(mainFile, []byte(output), 0644)
|
||||||
|
if err != nil {
|
||||||
|
app.Printf("Error while preparing main file: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
InfoPrint("\n%s package was installed successfully", packageName)
|
InfoPrint("\n%s package was installed successfully", packageName)
|
||||||
|
|
||||||
// build & run the server
|
// build & run the server
|
||||||
|
|
||||||
// go build
|
// go build
|
||||||
buildCmd := utils.CommandBuilder("go", "build")
|
buildCmd := utils.CommandBuilder("go", "build")
|
||||||
if targetDir[len(targetDir)-1] != os.PathSeparator || targetDir[len(targetDir)-1] != '/' {
|
if installTo[len(installTo)-1] != os.PathSeparator || installTo[len(installTo)-1] != '/' {
|
||||||
targetDir += utils.PathSeparator
|
installTo += utils.PathSeparator
|
||||||
}
|
}
|
||||||
buildCmd.Dir = targetDir + "backend"
|
buildCmd.Dir = installTo + "backend"
|
||||||
buildCmd.Stderr = os.Stderr
|
buildCmd.Stderr = os.Stderr
|
||||||
err = buildCmd.Start()
|
err = buildCmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -33,6 +33,9 @@ func DownloadZip(zipURL string, newDir string) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
var size int64
|
var size int64
|
||||||
finish := make(chan bool)
|
finish := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
finish <- true
|
||||||
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
print("\n|")
|
print("\n|")
|
||||||
|
@ -90,7 +93,8 @@ func DownloadZip(zipURL string, newDir string) (string, error) {
|
||||||
return "", ErrFileCopy.Format(err.Error())
|
return "", ErrFileCopy.Format(err.Error())
|
||||||
}
|
}
|
||||||
finish <- true
|
finish <- true
|
||||||
print("OK ", size, " bytes downloaded") //we keep that here so developer will always see in the terminal if a plugin downloads something
|
_ = size
|
||||||
|
//print("OK ", size, " bytes downloaded") //we keep that here so developer will always see in the terminal if a plugin downloads something or no ?
|
||||||
return fileName, nil
|
return fileName, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user