1.0.5 • Published 6 years ago

toguru-panel-cli v1.0.5

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

toguru-panel-cli

Filter exsting toguru toggles by property values

Setup up

  1. Run npm install toguru-panel-cli --save in your project

Configure & Use Toguru.js

  1. Include toguru-panel-cli in your project with const Toguru = require('toguru-panel-cli')
  2. Create a Toguru object with const toguru = Toguru(toguruToken)
    • Where toguruToken is your decrypted toguru token string.
  3. Call toguru.toggles() to receive an Observable of all toggles, and chain any filter predicates you want
  4. Chain .subscribe(toguru.sink) to your last observable filter operation to pretty print the resulting JSON

Examples

Run the included example with node example.js -t <your-toguru-token>.

Analagous to an SQL query, it:

"selects" toggles where

  • the toggle's team is gecloud
  • the toggle is fully rolled out
  • the toggle is defined for the classified-detail service.

toguru.toggles()                                        // SELECT * FROM TOGGLES
    .filter(toguru.teamToggles("gecloud"))              // WHERE (TOGGLES.TEAM = "gecloud"
    .filter(toguru.fullRollout)                         // AND TOGGLES.ROLLOUT_PERCENTAGE = 100
    .filter(toguru.toggleServices("classified-detail")) // AND TOGGLES.SERVICES = "classified-detail)"
    .subscribe(toguru.sink);                            // pretty prints result(s) to STDOUT

Running tests

  1. npm run test

Extend or write your own filters

To do this, write a predicate function that accepts a toggle object and returns true or false, and filter the toggles based on your predicate.

  • E.g. toguru.toggles().filter((toggle) => toggle.id === "my-toggle-id")

Contributing to the existing library

  1. Make a pull request with your changes describing what it does and why it is applicable to the general user base
  2. All library functionality should live in /lib/toguru.js, and extend the existing API
  3. Include tests for your new changes and make sure all old and new tests run with npm run test

Toggle JSON structure

Warning: some toggles are missing fields since they are user defined. Be sure to be aware of this when writing your own filters

{
	"id": "<toggle-id>",
	"tags": {
		"team": "<team-name>",
		"stack": "<stack-name>",
		"services": "<service-name(s)>"
	},
	"rolloutPercentage": <[0 - 100]>
}