Skip to content

Commit

Permalink
Respect batch flag in analytics hook (#1753)
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Oct 8, 2021
1 parent f00b219 commit 77062d2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,18 @@ OPTIONS
--backup-server-config-name=backup-server-config-name Name of custom resource with backup server config
--batch Batch mode. Running a command without end user interaction.
--password=password Authentication password for backup REST server
--ssh-key=ssh-key Private SSH key for authentication on SFTP server
--ssh-key-file=ssh-key-file Path to file with private SSH key for authentication on SFTP
server
--telemetry=on|off Enable or disable telemetry. This flag skips a prompt and
enable/disable telemetry
--username=username Username for authentication in backup REST server
EXAMPLES
Expand Down Expand Up @@ -727,6 +732,7 @@ OPTIONS
-d, --directory=directory Directory to store logs into
-h, --help show CLI help
-n, --chenamespace=chenamespace Eclipse Che Kubernetes namespace. Default to 'eclipse-che'
--batch Batch mode. Running a command without end user interaction.
--deployment-name=deployment-name [default: che] Eclipse Che deployment name
--k8spoddownloadimagetimeout=k8spoddownloadimagetimeout [default: 600000] Waiting time for Pod downloading image (in
Expand Down
8 changes: 6 additions & 2 deletions src/commands/server/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as Listr from 'listr'
import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL, DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants'
import { ChectlContext } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { cheNamespace } from '../../common-flags'
import { batch, cheNamespace, CHE_TELEMETRY } from '../../common-flags'
import { requestBackup, BackupServerConfig, getBackupServerType } from '../../api/backup-restore'
import { V1CheClusterBackup, V1CheClusterBackupStatus } from '../../api/typings/backup-restore-crds'
import { cli } from 'cli-ux'
Expand Down Expand Up @@ -110,6 +110,8 @@ export default class Backup extends Command {

static flags: flags.Input<any> = {
help: flags.help({ char: 'h' }),
telemetry: CHE_TELEMETRY,
batch,
chenamespace: cheNamespace,
[BACKUP_REPOSITORY_URL_KEY]: backupRepositoryUrl,
[BACKUP_REPOSITORY_PASSWORD_KEY]: backupRepositoryPassword,
Expand Down Expand Up @@ -143,7 +145,9 @@ export default class Backup extends Command {
cli.info(`Backup snapshot ID: ${ctx.snapshotId}`)
}
cli.info(getCommandSuccessMessage())
notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
}

private getBackupTasks(flags: any): Listr.ListrTask[] {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/server/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export default class Delete extends Command {
this.exit(0)
}

notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
this.exit(0)
}

Expand Down
4 changes: 3 additions & 1 deletion src/commands/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ export default class Deploy extends Command {
this.error(wrapCommandError(err))
}

notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
this.exit(0)
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/commands/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { cli } from 'cli-ux'
import * as Listr from 'listr'

import { ChectlContext } from '../../api/context'
import { cheDeployment, cheNamespace, k8sPodDownloadImageTimeout, K8SPODDOWNLOADIMAGETIMEOUT_KEY, k8sPodErrorRecheckTimeout, K8SPODERRORRECHECKTIMEOUT_KEY, k8sPodReadyTimeout, K8SPODREADYTIMEOUT_KEY, k8sPodWaitTimeout, K8SPODWAITTIMEOUT_KEY, listrRenderer, logsDirectory, LOG_DIRECTORY_KEY, skipKubeHealthzCheck } from '../../common-flags'
import { batch, cheDeployment, cheNamespace, k8sPodDownloadImageTimeout, K8SPODDOWNLOADIMAGETIMEOUT_KEY, k8sPodErrorRecheckTimeout, K8SPODERRORRECHECKTIMEOUT_KEY, k8sPodReadyTimeout, K8SPODREADYTIMEOUT_KEY, k8sPodWaitTimeout, K8SPODWAITTIMEOUT_KEY, listrRenderer, logsDirectory, LOG_DIRECTORY_KEY, skipKubeHealthzCheck } from '../../common-flags'
import { CheTasks } from '../../tasks/che'
import { ApiTasks } from '../../tasks/platforms/api'
import { findWorkingNamespace, getCommandSuccessMessage, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'
Expand All @@ -26,6 +26,7 @@ export default class Start extends Command {
static flags: flags.Input<any> = {
help: flags.help({ char: 'h' }),
chenamespace: cheNamespace,
batch,
'listr-renderer': listrRenderer,
'deployment-name': cheDeployment,
[K8SPODWAITTIMEOUT_KEY]: k8sPodWaitTimeout,
Expand Down Expand Up @@ -79,7 +80,9 @@ export default class Start extends Command {
this.error(wrapCommandError(err))
}

notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
this.exit(0)
}
}
4 changes: 3 additions & 1 deletion src/commands/server/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export default class Stop extends Command {
this.error(wrapCommandError(err))
}

notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
this.exit(0)
}
}
4 changes: 3 additions & 1 deletion src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export default class Update extends Command {
this.error(wrapCommandError(err))
}

notifyCommandCompletedSuccessfully()
if (!flags.batch) {
notifyCommandCompletedSuccessfully()
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ export const hook = async (options: { command: string, flags: any, config: IConf

// Prompt question if user allow chectl to collect data anonymous data.
if (!options.flags.telemetry && !segmentTelemetry) {
// Do not ask for enabling telemetry in batch mode. Just skip it if the telemetry flag is not set.
if (options.flags.batch) {
return
}
const confirmed = await cli.confirm('Enable CLI usage data to be sent to Red Hat online services. More info: https://developers.redhat.com/article/tool-data-collection [y/n]')
segmentTelemetry = confirmed ? 'on' : 'off'
configManager.setProperty(SegmentProperties.Telemetry, segmentTelemetry)
}

// In case of negative confirmation chectl don't collect any data
if (segmentTelemetry === 'off') {
// If not confirmed, chectl doesn't collect any data.
if (segmentTelemetry !== 'on') {
return
}

Expand Down

0 comments on commit 77062d2

Please sign in to comment.