budibase/packages/cli/src/analytics/index.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-03-29 18:40:17 +02:00
const Command = require("../structures/Command")
2021-03-30 12:50:49 +02:00
const { CommandWords } = require("../constants")
const { success, error } = require("../utils")
2021-03-30 11:50:42 +02:00
const AnalyticsClient = require("./Client")
2021-03-29 18:40:17 +02:00
const client = new AnalyticsClient()
async function optOut() {
try {
// opt them out
2021-03-30 11:50:42 +02:00
client.disable()
2021-03-30 12:50:49 +02:00
console.log(
success(
"Successfully opted out of Budibase analytics. You can opt in at any time by running 'budi analytics opt-in'"
2021-03-30 12:50:49 +02:00
)
)
} catch (err) {
console.log(
error(
"Error opting out of Budibase analytics. Please try again later.",
2021-03-30 12:50:49 +02:00
err
)
)
2021-03-29 18:40:17 +02:00
}
}
async function optIn() {
try {
// opt them in
client.enable()
2021-03-30 12:50:49 +02:00
console.log(
success(
"Successfully opted in to Budibase analytics. Thank you for helping us make Budibase better!"
2021-03-30 12:50:49 +02:00
)
)
} catch (err) {
console.log(
error("Error opting in to Budibase analytics. Please try again later.")
2021-03-30 12:50:49 +02:00
)
2021-03-29 18:40:17 +02:00
}
}
async function status() {
try {
console.log(success(`Budibase analytics ${client.status()}`))
} catch (err) {
2021-03-30 12:50:49 +02:00
console.log(
error("Error fetching analytics status. Please try again later.")
)
2021-03-29 18:40:17 +02:00
}
}
const command = new Command(`${CommandWords.ANALYTICS}`)
.addHelp("Control the analytics you send to Budibase.")
.addSubOption("--optin", "Opt in to sending analytics to Budibase", optIn)
.addSubOption("--optout", "Opt out of sending analytics to Budibase.", optOut)
2021-03-29 18:40:17 +02:00
.addSubOption(
"--status",
"Check whether you are currently opted in to Budibase analytics.",
2021-03-29 18:40:17 +02:00
status
)
exports.command = command