Skip to content

Mi-skam/issue3#7

Merged
mi-skam merged 3 commits into
mainfrom
mi-skam/issue3
Oct 26, 2023
Merged

Mi-skam/issue3#7
mi-skam merged 3 commits into
mainfrom
mi-skam/issue3

Conversation

@mi-skam

@mi-skam mi-skam commented Oct 26, 2023

Copy link
Copy Markdown
Contributor

Fixes #3

… questions about project name and template.

# Aider chat conversation:

USER: Right now i call nobj as cli and have to interactively choose between templates and projectNames, which will become a directory. I'd like to have partial completenes let's say `nobj test1` will skip the question for project name and `nobj test2 vanilla` will skip the question for project name AND template

ASSISTANT: To achieve this, we need to modify the way your CLI (Command Line Interface) handles arguments. We will use the `process.argv` array, which contains the command line arguments passed when the Node.js process was launched. The first element will be `node`, the second element will be the name of the JavaScript file, and the next elements will be any additional command line arguments.

We need to modify the following files:

1. `src/askProjectName.js`
2. `src/projectType.js`
3. `src/settings.js`

Here are the steps:

1. In `src/askProjectName.js`, we need to check if a project name was passed as a command line argument. If it was, we will use it and skip the question. If not, we will ask the question as before.

2. In `src/projectType.js`, we need to check if a project type was passed as a command line argument. If it was, we will use it and skip the question. If not, we will ask the question as before.

3. In `src/settings.js`, we need to modify the `settings` object to include the command line arguments.

Let's start with `src/askProjectName.js`. Here is the proposed change:

```javascript
src/askProjectName.js
<<<<<<< HEAD
    askProjectName.anonymousObjecta862c58f0105
        property
            name
=======
    const projectName = process.argv[2] || await inquirer.prompt({
        type: 'input',
        name: 'name',
        message: 'What is your project name?',
    });
    return projectName;
>>>>>>> updated
```

Next, let's modify `src/projectType.js`:

```javascript
src/projectType.js
<<<<<<< HEAD
    function
        projectType ()
=======
    const projectType = process.argv[3] || await inquirer.prompt({
        type: 'list',
        name: 'type',
        message: 'What is your project type?',
        choices: ['vanilla', 'react', 'vue', 'angular'],
    });
    return projectType;
>>>>>>> updated
```

Finally, let's modify `src/settings.js`:

```javascript
src/settings.js
<<<<<<< HEAD
    settings
        property
            projectName
            projectType
    variable
        settings
=======
    const settings = {
        projectName: process.argv[2],
        projectType: process.argv[3],
    };
    return settings;
>>>>>>> updated
```

Please note that this is a basic implementation and does not include any error checking or validation. You might want to add some checks to ensure that the provided project name and type are valid.

USER: InvalidEditBlock: edit failed!

src/askProjectName.js does not contain the *exact sequence* of HEAD lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The HEAD block needs to be EXACTLY the same as the lines in src/askProjectName.js with nothing missing!

src/askProjectName.js does not contain these 3 exact lines in a row:
```
    askProjectName.anonymousObjecta862c58f0105
        property
            name
```

ASSISTANT: I apologize for the confusion. Let's correct the changes.

Here are the correct changes for `src/askProjectName.js`:

```javascript
src/askProjectName.js
<<<<<<< HEAD
import inquirer from 'inquirer';
import { settings } from './settings.js';

export async function askProjectName() {
  const answer = await inquirer.prompt({
    name: 'project_name',
    type: 'input',
    message: 'Project name: ',
    default() {
      return 'nobj-project';
    },
  });
  settings.projectName = answer.project_name;
}
=======
import inquirer from 'inquirer';
import { settings } from './settings.js';

export async function askProjectName() {
  const projectName = process.argv[2];
  if (projectName) {
    settings.projectName = projectName;
  } else {
    const answer = await inquirer.prompt({
      name: 'project_name',
      type: 'input',
      message: 'Project name: ',
      default() {
        return 'nobj-project';
      },
    });
    settings.projectName = answer.project_name;
  }
}
>>>>>>> updated
```

And for `src/projectType.js`:

```javascript
src/projectType.js
<<<<<<< HEAD
import inquirer from 'inquirer';
import { settings } from './settings.js';
import { templateRepos } from './templates.js';

const projectTypes = Object.keys(templateRepos);

export async function projectType() {
  const answer = await inquirer.prompt({
    name: 'project_type',
    type: 'list',
    message: 'Choose your template: ',
    choices: projectTypes,
  });
  settings.projectType = answer.project_type;
}
=======
import inquirer from 'inquirer';
import { settings } from './settings.js';
import { templateRepos } from './templates.js';

const projectTypes = Object.keys(templateRepos);

export async function projectType() {
  const projectType = process.argv[3];
  if (projectType && projectTypes.includes(projectType)) {
    settings.projectType = projectType;
  } else {
    const answer = await inquirer.prompt({
      name: 'project_type',
      type: 'list',
      message: 'Choose your template: ',
      choices: projectTypes,
    });
    settings.projectType = answer.project_type;
  }
}
>>>>>>> updated
```

Please note that in `src/projectType.js`, we are checking if the provided project type is valid by checking if it exists in `projectTypes`. If it doesn't, we fall back to asking the user to choose a project type.
… available type if it's not provided in the command line arguments.

# Aider chat conversation:

USER: It's working for one argument (`nobj test1`) but not for two (`nobj test33 vanilla`). In the second case, i still got asked for the template type

ASSISTANT: I see. It seems like the issue is with the way we're checking for the project type in the command line arguments. Currently, we're checking if the project type exists and is included in the project types. However, if the project type is not provided, we're not skipping the question. We need to modify the `projectType.js` file to handle this case.

Here's what we need to do:

1. Modify the `projectType.js` file to check if the project type is provided in the command line arguments and if it's valid. If it's not provided or not valid, we should skip the question.

Here's the *edit block* for the change:

```javascript
src/projectType.js
<<<<<<< HEAD
  const projectType = process.argv[3];
  if (projectType && projectTypes.includes(projectType)) {
    settings.projectType = projectType;
  } else {
    const answer = await inquirer.prompt({
      name: 'project_type',
      type: 'list',
      message: 'Choose your template: ',
      choices: projectTypes,
    });
    settings.projectType = answer.project_type;
  }
=======
  const projectType = process.argv[3];
  if (projectType && projectTypes.includes(projectType)) {
    settings.projectType = projectType;
  } else if (!projectType) {
    settings.projectType = projectTypes[0];
  } else {
    const answer = await inquirer.prompt({
      name: 'project_type',
      type: 'list',
      message: 'Choose your template: ',
      choices: projectTypes,
    });
    settings.projectType = answer.project_type;
  }
>>>>>>> updated
```

This change will set the project type to the first available type if it's not provided in the command line arguments. If it's provided but not valid, it will still ask the question.
@mi-skam mi-skam merged commit 5241360 into main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an optional template parameter

1 participant