From b77250473f4c3e19dfb00c4aea94fad5c205b29b Mon Sep 17 00:00:00 2001 From: Sina Kashipazha Date: Thu, 18 Mar 2021 11:21:02 +0100 Subject: [PATCH 01/86] Added new option to change default cmk config file. (#70) Cloudmonkey command lets us use a different config file rather than the default one. This pull request added the same functionality to the cmk command. cmk -c ./my-config --- cmd/command.go | 1 + cmk.go | 3 ++- config/config.go | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/command.go b/cmd/command.go index ab8106ca..15d87143 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -68,6 +68,7 @@ Allowed flags: -o API response output format: json, text, table, column, csv -p Server profile -d Enable debug mode + -c different config file path Default commands: %s diff --git a/cmk.go b/cmk.go index 4f70cb55..eb94999b 100644 --- a/cmk.go +++ b/cmk.go @@ -45,10 +45,11 @@ func main() { showVersion := flag.Bool("v", false, "show version") debug := flag.Bool("d", false, "enable debug mode") profile := flag.String("p", "", "server profile") + configFilePath := flag.String("c", "", "config file path") flag.Parse() - cfg := config.NewConfig() + cfg := config.NewConfig(configFilePath) if *showVersion { fmt.Printf("%s %s (build: %s, %s)\n", cfg.Name(), cfg.Version(), GitSHA, BuildDate) diff --git a/config/config.go b/config/config.go index 664d99bd..592438a3 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,7 @@ import ( "net/http/cookiejar" "os" "path" + "path/filepath" "strconv" "time" @@ -324,10 +325,17 @@ func (c *Config) UpdateConfig(key string, value string, update bool) { } // NewConfig creates or reload config and loads API cache -func NewConfig() *Config { +func NewConfig(configFilePath *string) *Config { defaultConf := defaultConfig() defaultConf.Core = nil defaultConf.ActiveProfile = nil + if *configFilePath != "" { + defaultConf.ConfigFile, _ = filepath.Abs(*configFilePath) + if _, err := os.Stat(defaultConf.ConfigFile); os.IsNotExist(err) { + fmt.Println("Config file doesn't exist.") + os.Exit(1) + } + } cfg := reloadConfig(defaultConf) LoadCache(cfg) return cfg From 5d22bc49851cf404fcfdc394f3facd7ff304eb3b Mon Sep 17 00:00:00 2001 From: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com> Date: Thu, 13 May 2021 14:18:46 +0530 Subject: [PATCH 02/86] Inclusivity changes for CloudStack - Renamed default git branch name from 'master' to 'main' and some offensive words/terms as appropriate. (#76) --- README.md | 4 ++-- performrelease.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 02e52915..6c259c86 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## CloudMonkey [![Build Status](https://travis-ci.org/apache/cloudstack-cloudmonkey.svg?branch=master)](https://travis-ci.org/apache/cloudstack-cloudmonkey)[![](https://images.microbadger.com/badges/version/apache/cloudstack-cloudmonkey.svg)](https://hub.docker.com/r/apache/cloudstack-cloudmonkey)[![cloudmonkey](https://snapcraft.io/cloudmonkey/badge.svg)](https://snapcraft.io/cloudmonkey) +## CloudMonkey [![Build Status](https://travis-ci.org/apache/cloudstack-cloudmonkey.svg?branch=main)](https://travis-ci.org/apache/cloudstack-cloudmonkey)[![](https://images.microbadger.com/badges/version/apache/cloudstack-cloudmonkey.svg)](https://hub.docker.com/r/apache/cloudstack-cloudmonkey)[![cloudmonkey](https://snapcraft.io/cloudmonkey/badge.svg)](https://snapcraft.io/cloudmonkey) `cloudmonkey` :cloud::monkey_face: is a command line interface (CLI) for [Apache CloudStack](http://cloudstack.apache.org). @@ -57,7 +57,7 @@ Report issue(s) on the `user` mailing list and/or open a Github [issue](https:// 3. Commit your change 4. Write tests for your change if applicable 5. Run the tests, ensuring they all pass -6. Submit a [Pull Request](https://github.com/apache/cloudstack-cloudmonkey/pull/new/master) using Github +6. Submit a [Pull Request](https://github.com/apache/cloudstack-cloudmonkey/pull/new/main) using Github ### History diff --git a/performrelease.sh b/performrelease.sh index f87e0a78..26708c6e 100755 --- a/performrelease.sh +++ b/performrelease.sh @@ -19,7 +19,7 @@ version='TESTBUILD' sourcedir=~/cloudstack-cloudmonkey outputdir=/tmp/cloudstack-cloudmonkey-build/ -branch='master' +branch='main' tag='no' certid='X' committosvn='X' @@ -27,7 +27,7 @@ committosvn='X' usage(){ echo "usage: $0 -v version [-b branch] [-s source dir] [-o output dir] [-t] [-u] [-c] [-h]" echo " -v sets the version" - echo " -b sets the branch (defaults to 'master')" + echo " -b sets the branch (defaults to 'main')" echo " -s sets the source directory (defaults to $sourcedir)" echo " -o sets the output directory (defaults to $outputdir)" echo " -t tags the git repo with the version" From 63265499cda9d8ba52bf6f6efe353ca58edcaf2c Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 3 Aug 2021 11:03:50 +0530 Subject: [PATCH 03/86] Validate args passed - fail fast in case of invalid args (#79) --- cmd/set.go | 12 +++++++++++- cmk.go | 7 ++++++- config/config.go | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cmd/set.go b/cmd/set.go index 0cc1bf19..fef9b3f5 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -21,6 +21,7 @@ import ( "fmt" "reflect" "strings" + "errors" "github.com/apache/cloudstack-cloudmonkey/config" ) @@ -33,7 +34,7 @@ func init() { "prompt": {"🐵", "🐱", "random"}, "asyncblock": {"true", "false"}, "timeout": {"600", "1800", "3600"}, - "output": {"json", "text", "table", "column", "csv"}, + "output": config.GetOutputFormats(), "profile": {}, "url": {}, "username": {}, @@ -56,6 +57,15 @@ func init() { fmt.Println("Usage: set