From ff5c576bfab58c41cdace25ccd75855907c63608 Mon Sep 17 00:00:00 2001 From: Anton Sannikov Date: Wed, 13 Jan 2021 22:32:24 +0100 Subject: [PATCH] 13 Add scope config --- CHANGELOG.md | 4 +++ Readme.md | 59 ++++++++++++++++++++++++++++++++++++-- app/command/composer.go | 2 ++ app/command/xdebug.go | 2 ++ app/config/config.go | 7 ++++- app/config/globalConfig.go | 17 +++++++++-- main.go | 2 +- 7 files changed, 85 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37fd1cd..bb56172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.6.0 (14.01.2021) +- features + - 13 Add scope command config. User can hide unnecessary commands in global config file (composer, xdebug). + ## 1.5.7 (13.01.2021) - bugfix - 27 Fix shell type detection outside project diff --git a/Readme.md b/Readme.md index 009de48..4af68ce 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.5.3-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.5.7) +[![Release](https://img.shields.io/badge/release-1.5.3-brightgreen.svg)](https://github.com/asannikov/jumper/releases/tag/v1.6.0) It was not tested on Windows. @@ -31,7 +31,6 @@ PHP * Laravel artisan support * Docker extended managment * GIT routines -* Extendable jumper config options * Kubernetes management I'll highly appreciate for testing and any ideas where this tool can be useful. Please, write your suggestions or your experience in the issues. @@ -103,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.5.7 +https://github.com/asannikov/jumper/releases/tag/v1.6.0 ``` 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. @@ -147,6 +146,60 @@ implemented commands: shell Change shell type for a project ``` +# Project config example - jumper.json +``` +{ + "name": "Project Name", + "main_container": "php_container", + "start_command": "docker-compose up -d", + "path": "/var/www/src", + "xdebug_location": "local", + "xdebug_path_cli": "/path/to/project/config/xdebug_cli.ini", + "xdebug_path_fpm": "/path/to/project/config/xdebug_fpm.ini", + "shell": "bash" +} +``` + +all these options are managed using jumper command. **It's not recommended to edit manually.** + +# Global conifg file example - ~/.jumper.json +``` +{ + "projects": [ + { + "path": "/path/to/project1", + "name": "project1" + }, + { + "path": "/path/to/project2", + "name": "project2" + } + ], + "copyright_text": false, + "docker_service": "open --hide -a Docker", + "inactive_command_types": [ + "compose", + "xdebug" + ] +} +``` + +# Available options for global config ~/.jumper.json + +## Hide copyright text +Add `"copyright_text": false,` + +It can be done using jumper command though. + +## Permanent hiding some types of commands +add `"inactive_command_types": ["type1","type2"],` + +It can be done only directly in config file. + +here is a list of avalable values: +* `composer` - hides all composer commands +* `xdebug` - hides xdebug commands + # FAQ ## How to change shell type: Container might use only sh shell type and no bash. By default jumper uses `sh`. But you can use `bash` or even `csh`, `ksh` or `zsh`. Call `jumper shell` with no option and select shell type. It will be saved into project config `jumper.json` in `shell` node. diff --git a/app/command/composer.go b/app/command/composer.go index 1cf5bb3..4d78b2e 100644 --- a/app/command/composer.go +++ b/app/command/composer.go @@ -61,6 +61,7 @@ type callComposerCommandProjectConfig interface { GetProjectDockerPath() string GetProjectMainContainer() string SaveContainerNameToProjectConfig(string) error + GetCommandInactveStatus(string) bool } type callComposerCommandDialog interface { @@ -108,6 +109,7 @@ func CallComposerCommand(composercommand string, initf func(bool) string, cfg ca Aliases: []string{cmp.aliases[index]}, Usage: cmp.usage[index], Description: cmp.description[index], + Hidden: cfg.GetCommandInactveStatus("composer"), SkipFlagParsing: true, Action: func(c *cli.Context) (err error) { initf(true) diff --git a/app/command/xdebug.go b/app/command/xdebug.go index 3610fbe..8d03ae9 100644 --- a/app/command/xdebug.go +++ b/app/command/xdebug.go @@ -25,6 +25,7 @@ type xdebugProjectConfig interface { SaveDockerCliXdebugIniFilePath(string) error SaveDockerFpmXdebugIniFilePath(string) error SaveXDebugConifgLocaton(string) error + GetCommandInactveStatus(string) bool } type xdebugArgsProjectConfig interface { @@ -96,6 +97,7 @@ func XDebugCommand(xdebugAction string, initf func(bool) string, dockerStatus bo Usage: x.usage[xdebugAction], Description: x.description[xdebugAction], SkipFlagParsing: false, + Hidden: cfg.GetCommandInactveStatus("xdebug"), Action: func(c *cli.Context) (err error) { currentPath := initf(true) diff --git a/app/config/config.go b/app/config/config.go index 8e95d86..45dfc7c 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -98,6 +98,11 @@ func (c *Config) LoadConfig(seekProject bool) (err error) { return err } +// GetCommandInactveStatus gets command status +func (c *Config) GetCommandInactveStatus(cmd string) bool { + return c.globalConfig.GetCommandInactveStatus(cmd) +} + // FindProjectPathInJSON check if project path in the json func (c *Config) FindProjectPathInJSON(pc projectSettings) { c.globalConfig.FindProjectPathInJSON(func(p GlobalProjectConfig) (bool, error) { @@ -153,7 +158,7 @@ func (c *Config) AddProjectConfigFile() (err error) { } c.globalConfig.Projects = append(c.globalConfig.Projects, fpc) - + c.globalConfig.InactiveCommandTypes = []string{"composer", "php"} return c.fileSystem.SaveConfigFile(c.globalConfig, c.UserFile) } diff --git a/app/config/globalConfig.go b/app/config/globalConfig.go index 75fe7b3..7c4c14a 100644 --- a/app/config/globalConfig.go +++ b/app/config/globalConfig.go @@ -8,9 +8,10 @@ type GlobalProjectConfig struct { // GlobalConfig contains file config type GlobalConfig struct { - Projects []GlobalProjectConfig `json:"projects"` - Copyright bool `json:"copyright_text"` - DockerCommand string `json:"docker_service"` + Projects []GlobalProjectConfig `json:"projects"` + Copyright bool `json:"copyright_text"` + DockerCommand string `json:"docker_service"` + InactiveCommandTypes []string `json:"inactive_command_types"` } // SetDockerCommand define docker command @@ -56,6 +57,16 @@ func (g *GlobalConfig) GetProjectNameList() []string { return pl } +// GetCommandStatus checks command visibility +func (g *GlobalConfig) GetCommandInactveStatus(cmd string) bool { + for _, a := range g.InactiveCommandTypes { + if a == cmd { + return true + } + } + return false +} + // FindProjectPathInJSON find project path in json func (g *GlobalConfig) FindProjectPathInJSON(f func(GlobalProjectConfig) (bool, error)) error { for _, p := range g.Projects { diff --git a/main.go b/main.go index 7ce622b..e41091e 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "github.com/urfave/cli/v2" ) -const version = "1.5.7" +const version = "1.6.0" func main() {