This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added ability of handling environment variables in configuration file. $HOME and $PWD are expanded to actual values. - Added hidden command "tree" that can generate the full dbdeployer API. Using this feature, from now on we can compare API changes automatically. - Fixed visualization of sandboxes from catalog - Fixed minor code issues. - Added tests for environment variable replacement
- Loading branch information
1 parent
3f87321
commit 76a68c6
Showing
15 changed files
with
856 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// DBDeployer - The MySQL Sandbox | ||
// Copyright © 2006-2018 Giuseppe Maxia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func ShowTree(cmd *cobra.Command, args []string) { | ||
flags := cmd.Flags() | ||
api, _ := flags.GetBool("api") | ||
show_hidden, _ := flags.GetBool("show-hidden") | ||
if api { | ||
fmt.Println("This is the list of commands and modifiers available for dbdeployer") | ||
fmt.Println("") | ||
fmt.Println("{{dbdeployer --version}}") | ||
fmt.Println("# main") | ||
fmt.Println("{{dbdeployer -h }}") | ||
fmt.Println("") | ||
fmt.Println("{{dbdeployer tree }}") | ||
} | ||
traverse(rootCmd, "", 0, api, show_hidden) | ||
} | ||
|
||
func traverse(cmd *cobra.Command, parent string, level int, api, show_hidden bool) { | ||
subcommands := cmd.Commands() | ||
indent := strings.Repeat(" ", level*4) + "-" | ||
for _, c := range subcommands { | ||
hidden_flag := "" | ||
if c.Hidden || c.Name() == "help" { | ||
if show_hidden { | ||
hidden_flag = " (HIDDEN) " | ||
} else { | ||
continue | ||
} | ||
} | ||
size := len(c.Commands()) | ||
if api { | ||
if size > 0 || level == 0 { | ||
fmt.Printf("\n##%s%s\n", parent + " " + c.Name(), hidden_flag) | ||
} | ||
fmt.Printf("{{dbdeployer%s %s -h}}\n", parent, c.Name()) | ||
} else { | ||
fmt.Printf("%s %-20s%s\n", indent, c.Name(), hidden_flag) | ||
} | ||
if size > 0 { | ||
traverse(c, parent + " " + c.Name(), level + 1, api, show_hidden) | ||
} | ||
} | ||
} | ||
|
||
var treeCmd = &cobra.Command{ | ||
Use: "tree", | ||
Short: "shows command tree", | ||
Long: `This command is only used to create API documentation. | ||
You can, however, use it to show the command structure at a glance.`, | ||
Hidden : true, | ||
Run: ShowTree, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(treeCmd) | ||
treeCmd.PersistentFlags().Bool("api", false, "Writes API template") | ||
treeCmd.PersistentFlags().Bool("show-hidden", false, "Shows also hidden commands") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// DBDeployer - The MySQL Sandbox | ||
// Copyright © 2006-2018 Giuseppe Maxia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package common | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
type path_info struct { | ||
value string | ||
env_var string | ||
expected string | ||
} | ||
|
||
func TestReplaceLiteralHome(t *testing.T) { | ||
os.Setenv("HOME", "/home/Groucho") | ||
os.Setenv("PWD", "/var/lib/MarxBrothers") | ||
var paths = []path_info{ | ||
{"/home/Groucho/", "HOME", "$HOME/"}, | ||
{"/home/Groucho/path1/path2", "HOME", "$HOME/path1/path2"}, | ||
{"/home/Harpo/path1/path2", "HOME", "/home/Harpo/path1/path2"}, | ||
{"/var/lib/MarxBrothers/path1/path2", "PWD", "$PWD/path1/path2"}, | ||
{"/var/lib/MarxCousins/path1/path2", "PWD", "/var/lib/MarxCousins/path1/path2"}, | ||
} | ||
for _, p := range paths { | ||
value := p.value | ||
env_var := p.env_var | ||
expected := p.expected | ||
canary := ReplaceLiteralEnvVar(value, env_var) | ||
if expected == canary { | ||
t.Logf("ok %-35s %-10s =--> %-25s\n", value, "(" + env_var + ")", expected) | ||
} else { | ||
t.Logf("NOT OK %-35s %-10s =--> %-25s\n", value, "(" + env_var + ")", expected) | ||
t.Fail() | ||
} | ||
} | ||
for _, p := range paths { | ||
value := p.expected | ||
env_var := p.env_var | ||
expected := p.value | ||
canary := ReplaceEnvVar(value, env_var) | ||
if expected == canary { | ||
t.Logf("ok %-35s %-10s --=> %-25s\n", value, "(" + env_var + ")", expected) | ||
} else { | ||
t.Logf("NOT OK %-35s %-10s --=> %-25s\n", value, "(" + env_var + ")", expected) | ||
t.Fail() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.