Skip to content

Commit

Permalink
Merge branch '27-fix-shell' into 'master'
Browse files Browse the repository at this point in the history
Resolve "jumper shell outside project does not detect the project"

Closes #27

See merge request asannikov/mgt!27
  • Loading branch information
asannikov committed Jan 13, 2021
2 parents c39b167 + 07c4518 commit 7d3c572
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.5.7 (13.01.2021)
- bugfix
- 27 Fix shell type detection outside project

## 1.5.6 (13.01.2021)
- bugfix
- refactoring: changed files hierarchy in project
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.3-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.5.6)
[![Release](https://img.shields.io/badge/release-1.5.3-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.5.7)

It was not tested on Windows.

Expand Down Expand Up @@ -103,7 +103,7 @@ Every stable release has attached sources for "linux/amd64", "linux/386", "darwi

For example:
```
https://github.com/asannikov/jumper/releases/tag/v1.5.6
https://github.com/asannikov/jumper/releases/tag/v1.5.7
```
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.

Expand Down
12 changes: 11 additions & 1 deletion app/test.go → app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (tfs *testFileSystem) GetWd() (string, error) {
return tfs.getWd()
}

// TestDefinePaths tests definePaths
func TestDefinePaths(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand All @@ -116,6 +117,7 @@ func TestDefinePaths(t *testing.T) {
assert.EqualError(t, err, "Cannot read directory")
}

// TestSeekPathDefinePaths tests seekPath
func TestSeekPathDefinePaths(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand All @@ -133,6 +135,7 @@ func TestSeekPathDefinePaths(t *testing.T) {
assert.EqualError(t, err, "Cannot read directory")
}

// TestSeekPathLoadConfig tests seekPath
func TestSeekPathLoadConfig(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand All @@ -155,6 +158,7 @@ func TestSeekPathLoadConfig(t *testing.T) {
assert.EqualError(t, err, "Cannot read config file")
}

// TestSeekPathGetWd tests seekPath
func TestSeekPathGetWd(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand All @@ -180,6 +184,7 @@ func TestSeekPathGetWd(t *testing.T) {
assert.EqualError(t, err, "Cannot get current directory")
}

// TestSeekPathGetProjectNameList tests seekPath
func TestSeekPathGetProjectNameList(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -217,6 +222,7 @@ func TestSeekPathGetProjectNameList(t *testing.T) {
assert.Equal(t, 2, len(pl))
}

// TestSeekPathrunDialogCase1 tests seekPath
func TestSeekPathrunDialogCase1(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -255,6 +261,7 @@ func TestSeekPathrunDialogCase1(t *testing.T) {
assert.EqualError(t, err, "Error SelectProject dialog")
}

// TestSeekPathrunDialogCase2 tests seekPath
func TestSeekPathrunDialogCase2(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -305,6 +312,7 @@ func TestSeekPathrunDialogCase2(t *testing.T) {
assert.EqualError(t, err, "Is ok")
}

// TestSeekPathrunDialogCase3 tests seekPath
func TestSeekPathrunDialogCase3(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -358,6 +366,7 @@ func TestSeekPathrunDialogCase3(t *testing.T) {
assert.EqualError(t, err, "Is ok")
}

// TestSeekPathrunDialogCase4 tests seekPath
func TestSeekPathrunDialogCase4(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -411,6 +420,7 @@ func TestSeekPathrunDialogCase4(t *testing.T) {
assert.EqualError(t, err, "Add project name dialog error")
}

// TestSeekPathrunDialogCase5 tests seekPath
func TestSeekPathrunDialogCase5(t *testing.T) {
cfg := &config.Config{
ProjectFile: confgFile,
Expand Down Expand Up @@ -487,7 +497,7 @@ func TestSeekPathrunDialogCase5(t *testing.T) {
assert.EqualError(t, err, "Cannot save project config file")
}

// The same as TestSeekPathrunDialogCase5, but checks return nil for seek function
// TestSeekPathrunDialogCase6 tests seekPath. The same as TestSeekPathrunDialogCase5, but checks return nil for seek function
// see saveConfigFile return change
func TestSeekPathrunDialogCase6(t *testing.T) {
cfg := &config.Config{
Expand Down
43 changes: 30 additions & 13 deletions app/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import (
"github.com/urfave/cli/v2" // imports as package "cli"
)

type commandHandler func(chc commandHandleProjectConfig) string

type cliCommand struct {
usage map[string]string
aliases map[string]string
args map[string][]string
command map[string]string
command map[string]func(commandHandleProjectConfig) string
}

func (cli *cliCommand) GetCommand(cmd string) string {
return cli.command[cmd]
func (cli *cliCommand) GetCommand(cmd string, cfg commandHandleProjectConfig) string {
command := cli.command[cmd]
return command(cfg)
}

func (cli *cliCommand) GetArgs() map[string][]string {
Expand All @@ -35,6 +38,10 @@ type callCliCommandDialog interface {
SetMainContaner([]string) (int, string, error)
}

type commandHandleProjectConfig interface {
GetShell() string
}

// CallCliCommand calls a range of differnt cli commands
func CallCliCommand(commandName string, initf func(bool) string, cfg cliCommandHandleProjectConfig, d callCliCommandDialog, cl containerlist) *cli.Command {
clic := &cliCommand{
Expand All @@ -59,12 +66,22 @@ func CallCliCommand(commandName string, initf func(bool) string, cfg cliCommandH
"clinotty": []string{"-i"},
"clirootnotty": []string{"-u", "root", "-i"},
},
command: map[string]string{
"cli": "",
"sh": cfg.GetShell(),
"clinotty": "",
"cliroot": "",
"clirootnotty": "",
command: map[string]func(commandHandleProjectConfig) string{
"cli": func(c commandHandleProjectConfig) string {
return ""
},
"sh": func(c commandHandleProjectConfig) string {
return c.GetShell()
},
"clinotty": func(c commandHandleProjectConfig) string {
return ""
},
"cliroot": func(c commandHandleProjectConfig) string {
return ""
},
"clirootnotty": func(c commandHandleProjectConfig) string {
return ""
},
},
}

Expand Down Expand Up @@ -95,7 +112,7 @@ func CallCliCommand(commandName string, initf func(bool) string, cfg cliCommandH
}

type cliCommandInterface interface {
GetCommand(string) string
GetCommand(string, commandHandleProjectConfig) string
GetArgs() map[string][]string
}

Expand Down Expand Up @@ -125,11 +142,11 @@ func cliCommandHandle(index string, cfg cliCommandHandleProjectConfig, d cliComm

initArgs = append(initArgs, cfg.GetProjectMainContainer())

if c.GetCommand(index) != "" {
initArgs = append(initArgs, c.GetCommand(index))
if c.GetCommand(index, cfg) != "" {
initArgs = append(initArgs, c.GetCommand(index, cfg))
}

if c.GetCommand(index) == "" && a.Get(0) == "" {
if c.GetCommand(index, cfg) == "" && a.Get(0) == "" {
return []string{}, errors.New("Please specify a CLI command (ex. ls)")
}

Expand Down
2 changes: 1 addition & 1 deletion app/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type testCli struct {
command map[string]string
}

func (tc *testCli) GetCommand(cmd string) string {
func (tc *testCli) GetCommand(cmd string, cfg commandHandleProjectConfig) string {
return tc.command[cmd]
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli/v2"
)

const version = "1.5.6"
const version = "1.5.7"

func main() {

Expand Down

0 comments on commit 7d3c572

Please sign in to comment.