added warning to all CLI commands

This commit is contained in:
Conner Gallagher 2022-09-01 11:25:16 -06:00
parent 6614f09b40
commit 8021d5c900
5 changed files with 26 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import Big from "big.js";
import chalk from "chalk"; import chalk from "chalk";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { CURRENT_ANNOUNCEMENT } from "./announcement";
import { CliConfig, ConfigParameter, DEFAULT_CONFIG } from "./config"; import { CliConfig, ConfigParameter, DEFAULT_CONFIG } from "./config";
import { AuthorityMismatch } from "./types"; import { AuthorityMismatch } from "./types";
import { CommandContext } from "./types/context/context"; import { CommandContext } from "./types/context/context";
@ -74,6 +75,8 @@ abstract class BaseCommand extends Command {
const { flags } = await this.parse((<Input<any>>this.constructor) as any); const { flags } = await this.parse((<Input<any>>this.constructor) as any);
BaseCommand.flags = flags as any; BaseCommand.flags = flags as any;
console.log(CURRENT_ANNOUNCEMENT);
// setup logging // setup logging
this.silent = (flags as any).silent; this.silent = (flags as any).silent;
this.verbose = (flags as any).verbose; this.verbose = (flags as any).verbose;

View File

@ -5,6 +5,7 @@ import { SwitchboardDecimal } from "@switchboard-xyz/switchboard-v2";
import Big from "big.js"; import Big from "big.js";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import { CURRENT_ANNOUNCEMENT } from "./announcement";
import BaseCommand from "./BaseCommand"; import BaseCommand from "./BaseCommand";
abstract class OutputFileBaseCommand extends BaseCommand { abstract class OutputFileBaseCommand extends BaseCommand {
@ -40,25 +41,28 @@ abstract class OutputFileBaseCommand extends BaseCommand {
const { flags } = await this.parse((<Input<any>>this.constructor) as any); const { flags } = await this.parse((<Input<any>>this.constructor) as any);
BaseCommand.flags = flags as any; BaseCommand.flags = flags as any;
console.log(CURRENT_ANNOUNCEMENT);
const parsedPath = path.parse( const parsedPath = path.parse(
flags.outputFile.startsWith("/") || flags.outputFile.startsWith("C:") (flags as any).outputFile.startsWith("/") ||
? flags.outputFile (flags as any).outputFile.startsWith("C:")
: path.join(process.cwd(), flags.outputFile) ? (flags as any).outputFile
: path.join(process.cwd(), (flags as any).outputFile)
); );
this.outputBasePath = path.join(parsedPath.dir, parsedPath.name); this.outputBasePath = path.join(parsedPath.dir, parsedPath.name);
if (parsedPath.ext === ".json" || flags.json) { if (parsedPath.ext === ".json" || flags.json) {
this.outputJsonFile = `${this.outputBasePath}.json`; this.outputJsonFile = `${this.outputBasePath}.json`;
if (fs.existsSync(this.outputJsonFile) && !flags.force) { if (fs.existsSync(this.outputJsonFile) && !(flags as any).force) {
throw new Error( throw new Error(
`output json file already exists: ${this.outputJsonFile}` `output json file already exists: ${this.outputJsonFile}`
); );
} }
} }
if (parsedPath.ext === ".csv" || flags.csv) { if (parsedPath.ext === ".csv" || (flags as any).csv) {
this.outputCsvFile = `${this.outputBasePath}.csv`; this.outputCsvFile = `${this.outputBasePath}.csv`;
if (fs.existsSync(this.outputCsvFile) && !flags.force) { if (fs.existsSync(this.outputCsvFile) && !(flags as any).force) {
throw new Error( throw new Error(
`output csv file already exists: ${this.outputCsvFile}` `output csv file already exists: ${this.outputCsvFile}`
); );

View File

@ -3,7 +3,6 @@ import * as anchor from "@project-serum/anchor";
import { ACCOUNT_DISCRIMINATOR_SIZE } from "@project-serum/anchor/dist/cjs/coder"; import { ACCOUNT_DISCRIMINATOR_SIZE } from "@project-serum/anchor/dist/cjs/coder";
import { clusterApiUrl, Connection, Keypair, PublicKey } from "@solana/web3.js"; import { clusterApiUrl, Connection, Keypair, PublicKey } from "@solana/web3.js";
import { import {
DEFAULT_KEYPAIR,
prettyPrintAggregator, prettyPrintAggregator,
prettyPrintBufferRelayer, prettyPrintBufferRelayer,
prettyPrintCrank, prettyPrintCrank,
@ -31,6 +30,7 @@ import {
} from "@switchboard-xyz/switchboard-v2"; } from "@switchboard-xyz/switchboard-v2";
import chalk from "chalk"; import chalk from "chalk";
import * as path from "path"; import * as path from "path";
import { CURRENT_ANNOUNCEMENT } from "./announcement";
import { CliConfig } from "./config"; import { CliConfig } from "./config";
import { FsProvider } from "./types"; import { FsProvider } from "./types";
import { CommandContext } from "./types/context/context"; import { CommandContext } from "./types/context/context";
@ -64,6 +64,8 @@ abstract class PrintBaseCommand extends Command {
const { flags } = (await this.parse(this.constructor as any)) as any; const { flags } = (await this.parse(this.constructor as any)) as any;
// this.flags = flags; // this.flags = flags;
console.log(CURRENT_ANNOUNCEMENT);
// setup logging // setup logging
const level = flags.silent ? "error" : flags.verbose ? "debug" : "info"; const level = flags.silent ? "error" : flags.verbose ? "debug" : "info";
const logFilename = path.join(this.config.cacheDir, "log.txt"); const logFilename = path.join(this.config.cacheDir, "log.txt");

8
cli/src/announcement.ts Normal file
View File

@ -0,0 +1,8 @@
import chalk from "chalk";
// import { WARNING_ICON } from "./utils";
export const CURRENT_ANNOUNCEMENT = `${chalk.bgYellowBright(
chalk.bold(`WARNING`)
)}\n${chalk.blue(
`This package has been deprecated in favor of @switchboard-xyz/cli. Run the following commands to update:`
)}\n${`\tnpm uninstall -g @switchboard-xyz/switchboardv2-cli\n\tnpm install -g @switchboard-xyz/cli`}\nor\n\tyarn global remove @switchboard-xyz/switchboardv2-cli\n\tyarn global add @switchboard-xyz/cli\n`;

View File

@ -3,3 +3,5 @@ import chalk from "chalk";
export const CHECK_ICON = chalk.green("\u2714 "); export const CHECK_ICON = chalk.green("\u2714 ");
export const FAILED_ICON = chalk.red("\u2717 "); export const FAILED_ICON = chalk.red("\u2717 ");
export const WARNING_ICON = chalk.yellowBright("\u26A0 ");