Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
W.I.P.
Browse files Browse the repository at this point in the history
  • Loading branch information
pierce-h committed Sep 15, 2020
1 parent b40848d commit f31a158
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ const pjson = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.jso
export default abstract class BaseCommand extends Base {
public base = `${pjson.name}@${pjson.version}`;

public async apiClient(): Promise<APIClient> {
public async apiClient(debug = false): Promise<APIClient> {
const apiKey = await ApiKeyStore.get()
return new APIClient(apiKey);
return new APIClient(apiKey, debug);
}

/**
* Get the current user logged into the CLI
* @returns {Promise<AppUser>} A promise w/ the user object
*/
public async getCurrentUser(): Promise<AppUser> {
public async getCurrentUser(debug = false): Promise<AppUser> {
const apiKey = await ApiKeyStore.get()
const apiClient = new APIClient(apiKey);
const apiClient = new APIClient(apiKey, debug);
const user = await apiClient.user.getCurrent()

return user;
Expand Down
8 changes: 5 additions & 3 deletions src/commands/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ export default class Apps extends BaseCommand {
char: "h",
description: "Show help for the apps commands",
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

async run(): Promise<void> {
// When the -h flag is present the following line haults execution
this.parse(Apps);
const { flags } = this.parse(Apps);

// Verify user is logged in
try {
Expand All @@ -32,7 +34,7 @@ export default class Apps extends BaseCommand {
head: ['ID', 'Name', "Type"]
});

const apiClient = await this.apiClient()
const apiClient = await this.apiClient(flags.debug)
const apps = apiClient.apps.getAll();

(await apps).items.forEach((app) => {
Expand Down
10 changes: 6 additions & 4 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ export default class Info extends BaseCommand {
char: "h",
description: "Show help for the info command",
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

async run(): Promise<void> {
// When the -h flag is present the following line haults execution
this.parse(Info);
const { flags } = this.parse(Info);

// Verify user is logged in
try {
await this.getCurrentUser();
await this.getCurrentUser(flags.debug);
} catch {
await Login.run([])
}
Expand All @@ -34,7 +36,7 @@ export default class Info extends BaseCommand {
const pathToApp = process.cwd();
const app = await loadApp(pathToApp);

const apiClient = await this.apiClient()
const apiClient = await this.apiClient(flags.debug)

const platformApp = await apiClient.apps.getByName(app.manifest.name);
const paginatedDeployments = await apiClient.deployments.getAllForAppId(
Expand Down
8 changes: 5 additions & 3 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export default class Login extends BaseCommand {
char: "h",
description: "Show help for the login command",
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

async run(): Promise<void> {
// When the -h flag is present the following line haults execution
this.parse(Login);
const { flags } = this.parse(Login);

const apiKey = await cli.prompt(
"Please enter your API key",
Expand All @@ -35,7 +37,7 @@ export default class Login extends BaseCommand {

try {
cli.action.start("Verifying account");
await this.getCurrentUser();
await this.getCurrentUser(flags.debug);
} catch (error) {
await ApiKeyStore.clear();
const err = error as ApiClientError;
Expand Down
12 changes: 7 additions & 5 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import { loadApp } from "@shipengine/connect-loader";
import Login from './login';
import { ApiClientErrors } from '../core/api-client'

export default class Info extends BaseCommand {
export default class Logs extends BaseCommand {
public static description = "Get the logs for your app";

static flags = {
help: flags.help({
char: "h",
description: "Show help for the logs command",
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

async run(): Promise<void> {
// When the -h flag is present the following line haults execution
this.parse(Info);
const { flags } = this.parse(Logs);

// Verify user is logged in
try {
await this.getCurrentUser();
await this.getCurrentUser(flags.debug);
} catch {
await Login.run([])
}
Expand All @@ -33,7 +35,7 @@ export default class Info extends BaseCommand {
const pathToApp = process.cwd();
const app = await loadApp(pathToApp);

const apiClient = await this.apiClient()
const apiClient = await this.apiClient(flags.debug)

const platformApp = await apiClient.apps.getByName(app.manifest.name);
const paginatedDeployments = await apiClient.deployments.getAllForAppId(
Expand Down
8 changes: 5 additions & 3 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export default class Publish extends BaseCommand {
description: "Skip running the test before publishing",
default: false,
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

Expand All @@ -38,12 +40,12 @@ export default class Publish extends BaseCommand {

// Verify user is logged in
try {
await this.getCurrentUser();
await this.getCurrentUser(flags.debug);
} catch {
await Login.run([])
}

const apiClient = await this.apiClient()
const apiClient = await this.apiClient(flags.debug)

// Run test in fail fast mode unless skipped
if (!flags["skip-tests"]) await Test.run(["-f"]);
Expand Down
8 changes: 5 additions & 3 deletions src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ export default class Whoami extends BaseCommand {
char: "h",
description: "Show help for the whoami command",
}),
debug: flags.help({
debug: flags.boolean({
char: "d",
description: "Show network debugging information",
default: false,
hidden: true
}),
};

async run(): Promise<void> {
// When the -h flag is present the following line haults execution
this.parse(Whoami);
const { flags } = this.parse(Whoami);

try {
const appUser = await this.getCurrentUser();
const appUser = await this.getCurrentUser(flags.debug);

this.log(`You are currently logged in as: ${appUser.name}`);
} catch (error) {
Expand Down

0 comments on commit f31a158

Please sign in to comment.