Skip to content

Commit

Permalink
refactor(cli): get rid of sywac dependency and improve CLI-code tests
Browse files Browse the repository at this point in the history
Some of our oldest tech-debt there... It'll be good to have this over
with. This will unblock a few small improvements but I figure it's best
to do just the refactor first.
  • Loading branch information
edvald authored and eysi09 committed Aug 11, 2020
1 parent 3cb4da6 commit bd291d0
Show file tree
Hide file tree
Showing 69 changed files with 2,266 additions and 1,264 deletions.
6 changes: 4 additions & 2 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The following option flags can be used with any of the CLI commands:

| Argument | Alias | Type | Description |
| -------- | ----- | ---- | ----------- |
| `--root` | `-r` | string | Override project root directory (defaults to working directory).
| `--root` | `-r` | path | Override project root directory (defaults to working directory). Can be absolute or relative to current directory.
| `--silent` | `-s` | boolean | Suppress log output. Same as setting --logger-type=quiet.
| `--env` | `-e` | string | The environment (and optionally namespace) to work against.
| `--logger-type` | | `quiet` `basic` `fancy` `fullscreen` `json` | Set logger type. fancy updates log lines in-place when their status changes (e.g. when tasks complete), basic appends a new log line when a log line's status changes, json same as basic, but renders log lines as JSON, quiet suppresses all log output, same as --silent.
Expand All @@ -30,6 +30,8 @@ The following option flags can be used with any of the CLI commands:
| `--yes` | `-y` | boolean | Automatically approve any yes/no prompts during execution.
| `--force-refresh` | | boolean | Force refresh of any caches, e.g. cached provider statuses.
| `--var` | | array:string | Set a specific variable value, using the format <key>=<value>, e.g. `--var some-key=custom-value`. This will override any value set in your project configuration. You can specify multiple variables by separating with a comma, e.g. `--var key-a=foo,key-b="value with quotes"`.
| `--version` | `-v` | boolean | Show the current CLI version.
| `--help` | `-h` | boolean | Show help

### garden build

Expand Down Expand Up @@ -63,7 +65,7 @@ Examples:

| Argument | Alias | Type | Description |
| -------- | ----- | ---- | ----------- |
| `--force` | | boolean | Force rebuild of module(s).
| `--force` | `-f` | boolean | Force rebuild of module(s).
| `--watch` | `-w` | boolean | Watch for changes in module(s) and auto-build.

#### Outputs
Expand Down
3 changes: 2 additions & 1 deletion garden-service/bin/garden
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ require("source-map-support").install()

const cli = require("../build/src/cli/cli")

cli.run()
// tslint:disable-next-line: no-floating-promises
cli.runCli()
3 changes: 2 additions & 1 deletion garden-service/bin/garden-debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ require("source-map-support").install()

const cli = require("../build/src/cli/cli")

cli.run()
// tslint:disable-next-line: no-floating-promises
cli.runCli()
5 changes: 0 additions & 5 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"supertest": "^4.0.2",
"sywac": "^1.3.0",
"tar": "^6.0.2",
"terminal-link": "^2.1.1",
"titleize": "^2.1.0",
Expand Down
6 changes: 6 additions & 0 deletions garden-service/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AnalyticsType } from "./analytics-types"
import dedent from "dedent"
import { getGitHubUrl } from "../docs/common"
import { InternalError } from "../exceptions"
import { Profile } from "../util/profiling"

const API_KEY = process.env.ANALYTICS_DEV ? SEGMENT_DEV_API_KEY : SEGMENT_PROD_API_KEY

Expand Down Expand Up @@ -115,6 +116,7 @@ export interface SegmentEvent {
* @export
* @class AnalyticsHandler
*/
@Profile()
export class AnalyticsHandler {
private static instance?: AnalyticsHandler
private segment: any
Expand Down Expand Up @@ -443,6 +445,10 @@ export class AnalyticsHandler {
* @memberof AnalyticsHandler
*/
async flush() {
if (!this.analyticsEnabled()) {
return
}

// This is to handle an edge case where Segment flushes the events (e.g. at the interval) and
// Garden exits at roughly the same time. When that happens, `segment.flush()` will return immediately since
// the event queue is already empty. However, the network request might not have fired and the events are
Expand Down
Loading

0 comments on commit bd291d0

Please sign in to comment.