diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2b796..e78c825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## 1.7.3 (19.01.2021) +- bugfix + - fix sync destination option + +- features + - add force flag for copyfrom + ## 1.7.2 (17.01.2021) - bugfix - refactoring for commands, added general type that contains all func parameters diff --git a/Readme.md b/Readme.md index ecc49ff..5aa5bf7 100644 --- a/Readme.md +++ b/Readme.md @@ -6,7 +6,7 @@ I was inspired by [Mark's Shust](https://github.com/markshust/docker-magento) so [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/asannikov/jumper/blob/master/LICENSE) [![Build Status](https://travis-ci.com/asannikov/jumper.svg?branch=master)](https://travis-ci.com/asannikov/jumper) -[![Release](https://img.shields.io/badge/release-1.7.2-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.7.2) +[![Release](https://img.shields.io/badge/release-1.7.3-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.7.3) It was not tested on Windows. @@ -102,7 +102,7 @@ Every stable release has attached sources for "linux/amd64", "linux/386", "darwi For example: ``` -https://github.com/asannikov/jumper/releases/tag/v1.7.2 +https://github.com/asannikov/jumper/releases/tag/v1.7.3 ``` Find related source there and download it. Now you can place use source at any place you want on your machine or make it global in a standard way. diff --git a/app/command/sync.go b/app/command/sync.go index 26bdf5b..dede511 100644 --- a/app/command/sync.go +++ b/app/command/sync.go @@ -4,11 +4,15 @@ import ( "errors" "fmt" "os" + "path/filepath" "strings" "github.com/urfave/cli/v2" ) +const syncCopyFrom = "copyfrom" +const syncCopyTo = "copyto" + type sync struct { usage map[string]string aliases map[string]string @@ -33,10 +37,12 @@ type syncProjectConfig interface { func getSyncArgs(cfg syncProjectConfig, direction string, syncPath string, projectRoot string) []string { projectRoot = strings.TrimRight(projectRoot, string(os.PathSeparator)) - args := []string{"cp", projectRoot + syncPath, cfg.GetProjectMainContainer() + ":" + strings.TrimRight(cfg.GetProjectDockerPath(), string(os.PathSeparator)) + syncPath} + targetPath := filepath.Dir(syncPath) + + args := []string{"cp", projectRoot + syncPath, cfg.GetProjectMainContainer() + ":" + strings.TrimRight(cfg.GetProjectDockerPath(), string(os.PathSeparator)) + targetPath} - if direction == "copyfrom" { - args = []string{"cp", cfg.GetProjectMainContainer() + ":" + strings.TrimRight(cfg.GetProjectDockerPath(), string(os.PathSeparator)) + syncPath, projectRoot + syncPath} + if direction == syncCopyFrom { + args = []string{"cp", cfg.GetProjectMainContainer() + ":" + strings.TrimRight(cfg.GetProjectDockerPath(), string(os.PathSeparator)) + syncPath, projectRoot + targetPath} } return args @@ -60,25 +66,36 @@ func SyncCommand(direction string, cfg syncProjectConfig, d syncCommandDialog, o s := &sync{ usage: map[string]string{ - "copyto": "Sync local -> docker container, set related path, ie `vendor/folder/` for syncing as a parameter, or use --all to sync all project", - "copyfrom": "Sync docker container -> local, set related path, ie `vendor/folder/` for syncing as a parameter, or use --all to sync all project", + syncCopyTo: "Sync local -> docker container, set related path, ie `vendor/folder/` for syncing as a parameter, or use --all to sync all project", + syncCopyFrom: "Sync docker container -> local, set related path, ie `vendor/folder/` for syncing as a parameter, or use --all to sync all project", }, aliases: map[string]string{ - "copyto": "cpt", - "copyfrom": "cpf", + syncCopyTo: "cpt", + syncCopyFrom: "cpf", }, description: map[string]string{ - "copyto": "phpContainer is taken from project config file", - "copyfrom": "phpContainer is taken from project config file, php and composer commands will be found automatically", + syncCopyTo: "phpContainer is taken from project config file", + syncCopyFrom: "phpContainer is taken from project config file, php and composer commands will be found automatically", }, } + flags := []cli.Flag{} + + if direction == syncCopyFrom { + flags = append(flags, &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force create directory for file if it does not exist", + }) + } + return &cli.Command{ Name: direction, Aliases: []string{s.aliases[direction]}, Usage: s.usage[direction], Description: s.description[direction], - SkipFlagParsing: true, + SkipFlagParsing: false, + Flags: flags, Action: func(c *cli.Context) (err error) { syncPath := c.Args().First() @@ -105,11 +122,20 @@ func SyncCommand(direction string, cfg syncProjectConfig, d syncCommandDialog, o args := getSyncArgs(cfg, direction, syncPath, currentPath) + if direction == syncCopyFrom && c.Bool("f") == true { + fmt.Printf("Path %s was created", args[2]+filepath.Base(syncPath)) + err = os.MkdirAll(args[2]+filepath.Base(syncPath), os.ModePerm) + } + + if err != nil { + return err + } + if err = execCommand("docker", args, c.App); err != nil { return err } - if direction == "copyto" { + if direction == syncCopyTo { fmt.Printf("Completed copying %s files from host to container %s \n", syncPath, cfg.GetProjectMainContainer()) } else { fmt.Printf("Completed copying %s from container %s to host\n", syncPath, cfg.GetProjectMainContainer()) diff --git a/app/command/sync_test.go b/app/command/sync_test.go index 2b36d63..6b94812 100644 --- a/app/command/sync_test.go +++ b/app/command/sync_test.go @@ -45,44 +45,44 @@ func TestGetSyncArgs(t *testing.T) { projectDockerPath: "/var/www/html/", } args := getSyncArgs(cfg, "copyfrom", getSyncPath("/vendor/path"), "/path/to/local/project/") - assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path /path/to/local/project/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path /path/to/local/project/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyfrom", getSyncPath("/vendor/path/file.php"), "/path/to/local/project/") - assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path/file.php /path/to/local/project/vendor/path/file.php", strings.Join(args, " ")) + assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path/file.php /path/to/local/project/vendor/path", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path/file.php"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path/file.php phpfmp:/var/www/html/vendor/path/file.php", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path/file.php phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path/"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path"), "/path/to/local/project") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("--all"), "/path/to/local/project") - assert.Equal(t, "cp /path/to/local/project/./ phpfmp:/var/www/html/./", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/./ phpfmp:/var/www/html/", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyfrom", getSyncPath("--all"), "/path/to/local/project") - assert.Equal(t, "cp phpfmp:/var/www/html/./ /path/to/local/project/./", strings.Join(args, " ")) + assert.Equal(t, "cp phpfmp:/var/www/html/./ /path/to/local/project/", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyfrom", getSyncPath("/vendor/path"), "/path/to/local/project/") - assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path /path/to/local/project/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path /path/to/local/project/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyfrom", getSyncPath("vendor/path/file.php"), "/path/to/local/project/") - assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path/file.php /path/to/local/project/vendor/path/file.php", strings.Join(args, " ")) + assert.Equal(t, "cp phpfmp:/var/www/html/vendor/path/file.php /path/to/local/project/vendor/path", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("vendor/path/file.php"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path/file.php phpfmp:/var/www/html/vendor/path/file.php", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path/file.php phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("vendor/path/"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path"), "/path/to/local/project/") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) args = getSyncArgs(cfg, "copyto", getSyncPath("/vendor/path"), "/path/to/local/project") - assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor/path", strings.Join(args, " ")) + assert.Equal(t, "cp /path/to/local/project/vendor/path phpfmp:/var/www/html/vendor", strings.Join(args, " ")) } diff --git a/main.go b/main.go index de9f4c2..d49801d 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "github.com/urfave/cli/v2" ) -const version = "1.7.2" +const version = "1.7.3" func main() {