Skip to content

Commit

Permalink
update to realm
Browse files Browse the repository at this point in the history
Signed-off-by: steviebps <stephenwodecki@gmail.com>
  • Loading branch information
steviebps committed Oct 9, 2021
1 parent 3999dc1 commit cc29322
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 51 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# chambr
# realm

[![release](https://github.com/steviebps/rein/actions/workflows/go.yml/badge.svg)](https://github.com/steviebps/rein/actions/workflows/go.yml)

```go get -u github.com/steviebps/chambr```
```go get -u github.com/steviebps/realm```


## starter configs

### a basic chamber file
```wget -O $HOME/.chambr/masterChamber.json https://raw.githubusercontent.com/steviebps/rein/master/configs/masterChamber.json```
```wget -O $HOME/.realm/masterChamber.json https://raw.githubusercontent.com/steviebps/rein/master/configs/masterChamber.json```


## example commands

### build
```chambr build -o /path/to/your/directory```
```realm build -o /path/to/your/directory```

with forced directory creation

```chambr build -o /path/to/your/directory --force```
```realm build -o /path/to/your/directory --force```

#### Pipe into an archive:
```chambr build | tar zcf archive.tar.gz -T -```
```realm build | tar zcf archive.tar.gz -T -```

### print

#### Pretty prints your global chamber to stdout:
```chambr print -p```
```realm print -p```

#### Print your global chamber to file:
```chambr print -o /path/to/your/file.json```
```realm print -o /path/to/your/file.json```
14 changes: 7 additions & 7 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"path/filepath"

"github.com/spf13/cobra"
"github.com/steviebps/rein/internal/logger"
rein "github.com/steviebps/rein/pkg"
"github.com/steviebps/rein/utils"
"github.com/steviebps/realm/internal/logger"
realm "github.com/steviebps/realm/pkg"
"github.com/steviebps/realm/utils"
)

var chamberName string
Expand All @@ -21,7 +21,7 @@ var buildCmd = &cobra.Command{
Use: "build",
Short: "Build chambers with inherited toggles",
Long: `Build command will take your chamber configs and compile them with their inherited values`,
Example: "rein build -o /path/to/your/directory",
Example: "realm build -o /path/to/your/directory",
Run: func(cmd *cobra.Command, args []string) {
outputDir, _ := cmd.Flags().GetString("output-dir")
forceCreateDir, _ := cmd.Flags().GetBool("force")
Expand All @@ -44,7 +44,7 @@ var buildCmd = &cobra.Command{
os.Mkdir(fullPath, 0700)
} else {
buildCmdError(fmt.Sprintf("Directory %v does not exist", fullPath))
logger.InfoString(fmt.Sprintf("\nTry running: \"rein build --output-dir %v --force\" to force create the directory", outputDir))
logger.InfoString(fmt.Sprintf("\nTry running: \"realm build --output-dir %v --force\" to force create the directory", outputDir))
os.Exit(1)
}
}
Expand All @@ -64,9 +64,9 @@ func getOutputDirectory(outputDir string) (string, error) {
return filepath.Abs(outputDir)
}

func build(parent *rein.Chamber, fullPath string, version string, cmd *cobra.Command) {
func build(parent *realm.Chamber, fullPath string, version string, cmd *cobra.Command) {

parent.TraverseAndBuild(func(c rein.Chamber) bool {
parent.TraverseAndBuild(func(c realm.Chamber) bool {

searchingByName := chamberName != ""
foundByName := chamberName == c.Name
Expand Down
6 changes: 3 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/steviebps/rein/internal/logger"
rein "github.com/steviebps/rein/pkg"
"github.com/steviebps/realm/internal/logger"
realm "github.com/steviebps/realm/pkg"
)

var getCmdError = logger.ErrorWithPrefix("Error running get command: ")
Expand All @@ -22,7 +22,7 @@ var getCmd = &cobra.Command{
toggle, _ := cmd.Flags().GetString("toggle")
chamberName, _ = cmd.Flags().GetString("chamber")

globalChamber.TraverseAndBuild(func(c rein.Chamber) bool {
globalChamber.TraverseAndBuild(func(c realm.Chamber) bool {
if c.Name == chamberName {
value = c.GetToggleValue(toggle, version)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/steviebps/rein/internal/logger"
"github.com/steviebps/rein/utils"
"github.com/steviebps/realm/internal/logger"
"github.com/steviebps/realm/utils"
)

var printCmdError = logger.ErrorWithPrefix("Error running print command: ")
Expand Down
28 changes: 14 additions & 14 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
"github.com/spf13/cobra"

homedir "github.com/mitchellh/go-homedir"
"github.com/steviebps/rein/internal/logger"
rein "github.com/steviebps/rein/pkg"
utils "github.com/steviebps/rein/utils"
"github.com/steviebps/realm/internal/logger"
realm "github.com/steviebps/realm/pkg"
utils "github.com/steviebps/realm/utils"
)

var home string
var cfgFile string
var globalChamber = rein.Chamber{Toggles: map[string]*rein.Toggle{}, Children: []*rein.Chamber{}}
var globalChamber = realm.Chamber{Toggles: map[string]*realm.Toggle{}, Children: []*realm.Chamber{}}

// Version the version of rein
// Version the version of realm
var Version = "development"

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "rein",
Use: "realm",
Short: "Local and remote configuration management",
Long: `CLI for managing application configuration of local and remote JSON files`,
PersistentPreRun: configPreRun,
Expand All @@ -35,7 +35,7 @@ var rootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
logger.ErrorString(fmt.Sprintf("Error while starting rein: %v", err))
logger.ErrorString(fmt.Sprintf("Error while starting realm: %v", err))
os.Exit(1)
}
}
Expand All @@ -51,23 +51,23 @@ func init() {
}

rootCmd.SetVersionTemplate(`{{printf "%s\n" .Version}}`)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "rein configuration file")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "realm configuration file")
rootCmd.PersistentFlags().String("app-version", "", "runs all commands with a specified version")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
rein.SetConfigFile(cfgFile)
realm.SetConfigFile(cfgFile)
} else {
rein.AddConfigPath("./")
rein.AddConfigPath(home + "/.rein/")
rein.SetConfigName("rein.json")
realm.AddConfigPath("./")
realm.AddConfigPath(home + "/.realm/")
realm.SetConfigName("realm.json")
}

// If a config file is found, read it in.
if err := rein.ReadInConfig(false); err != nil {
if err := realm.ReadInConfig(false); err != nil {
logger.ErrorString(err.Error())
os.Exit(1)
}
Expand All @@ -81,7 +81,7 @@ func retrieveRemoteConfig(url string) (*http.Response, error) {
func configPreRun(cmd *cobra.Command, args []string) {
var jsonFile io.ReadCloser
var err error
chamberFile := rein.StringValue("chamber", "")
chamberFile := realm.StringValue("chamber", "")

validURL, url := utils.IsURL(chamberFile)
if validURL {
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions examples/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import (
"log"
"net/http"

rein "github.com/steviebps/rein/pkg"
realm "github.com/steviebps/realm/pkg"
)

func handler(w http.ResponseWriter, r *http.Request) {
message := rein.StringValue("message", "DEFAULT")
message := realm.StringValue("message", "DEFAULT")
w.Write([]byte(message))
}

func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", handler)

rein.SetVersion("v1.0.0")
realm.SetVersion("v1.0.0")

if err := rein.AddConfigPath("./"); err != nil {
if err := realm.AddConfigPath("./"); err != nil {
log.Fatal(err)
}

if err := rein.SetConfigName("chambers.json"); err != nil {
if err := realm.SetConfigName("chambers.json"); err != nil {
log.Fatal(err)
}

if err := rein.ReadInConfig(true); err != nil {
if err := realm.ReadInConfig(true); err != nil {
log.Fatal(err)
}

port := rein.Float64Value("port", 3000)
port := realm.Float64Value("port", 3000)

log.Println("Listening on :", port)
err := http.ListenAndServe(fmt.Sprintf(":%d", int(port)), mux)
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package logger
import (
"fmt"

"github.com/steviebps/rein/internal/colors"
"github.com/steviebps/realm/internal/colors"
)

func ErrorString(e string) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/
package main

import "github.com/steviebps/rein/cmd"
import "github.com/steviebps/realm/cmd"

func main() {
cmd.Execute()
Expand Down
2 changes: 1 addition & 1 deletion pkg/chamber.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion pkg/chamber_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/override.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion pkg/override_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions pkg/rein.go → pkg/realm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"errors"
Expand All @@ -9,7 +9,7 @@ import (
"sync"

"github.com/fsnotify/fsnotify"
"github.com/steviebps/rein/utils"
"github.com/steviebps/realm/utils"
"golang.org/x/mod/semver"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/toggle.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rein
package realm

import (
"encoding/json"
Expand All @@ -9,7 +9,7 @@ import (
)

// Toggle is a feature switch/toggle structure for holding
// its name, value, type and any overrides to be parsed by the applicable rein sdk
// its name, value, type and any overrides to be parsed by the applicable realm sdk
type Toggle struct {
Name string `json:"name"`
ToggleType string `json:"type"`
Expand Down

0 comments on commit cc29322

Please sign in to comment.