Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt deploy command for subgraph name and select product #1294

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-buckets-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': minor
---

Prompt deploy command for subgraph name and select product
32 changes: 23 additions & 9 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { URL } from 'url';
import { Args, Command, Flags, ux } from '@oclif/core';
import { print } from 'gluegun';
import { print, prompt } from 'gluegun';
import { identifyDeployKey } from '../command-helpers/auth';
import { createCompiler } from '../command-helpers/compiler';
import * as DataSourcesExtractor from '../command-helpers/data-sources';
Expand All @@ -20,13 +20,13 @@ const headersFlag = Flags.custom<Record<string, string>>({
default: {},
});

const productOptions = ['subgraph-studio', 'hosted-service'];

export default class DeployCommand extends Command {
static description = 'Deploys a subgraph to a Graph node.';

static args = {
'subgraph-name': Args.string({
required: true,
}),
'subgraph-name': Args.string({}),
'subgraph-manifest': Args.string({
default: 'subgraph.yaml',
}),
Expand All @@ -39,7 +39,7 @@ export default class DeployCommand extends Command {

product: Flags.string({
summary: 'Select a product for which to authenticate.',
options: ['subgraph-studio', 'hosted-service'],
options: productOptions,
}),
studio: Flags.boolean({
summary: 'Shortcut for "--product subgraph-studio".',
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class DeployCommand extends Command {

async run() {
const {
args: { 'subgraph-name': subgraphName, 'subgraph-manifest': manifest },
args: { 'subgraph-name': subgraphNameArg, 'subgraph-manifest': manifest },
flags: {
product: productFlag,
studio,
Expand All @@ -114,15 +114,29 @@ export default class DeployCommand extends Command {
},
} = await this.parse(DeployCommand);

const subgraphName =
subgraphNameArg ||
(await ux.prompt('What is the subgraph name?', {
required: true,
}));

// We are given a node URL, so we prioritize that over the product flag
const product = nodeFlag
? productFlag
: studio
? 'subgraph-studio'
: productFlag ||
(await ux.prompt('Which product to deploy for?', {
required: true,
}));
(await prompt
.ask([
{
name: 'product',
message: 'Which product to deploy for?',
required: true,
type: 'select',
choices: productOptions,
},
])
.then(({ product }) => product as string));

try {
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
Expand Down