question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not To Prompt Input Based on Previous Certain Input Value

See original GitHub issue
  • Cookiecutter version: 1.7.2
  • Template project url: N/A
  • Python version: 3.7.7
  • Operating System: windows

Description:

I want to provide two database options to choose.

{
  ...
  "database": [
    "sqlite",
    "postgres"
  ],
  "db_user": "postgres",
  "db_passwd": "password",
  "db_addr": "127.0.0.1",
  "db_name": "{{cookiecutter.app_slug}}"
}

But for sqlite, I don’t need to know these

{
  "db_user": "postgres",
  "db_passwd": "password",
  "db_addr": "127.0.0.1",
  "db_name": "{{cookiecutter.app_slug}}"
}

So how can I decide not to prompt these input based on certain input value?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

6reactions
Chobitocommented, Dec 14, 2021

@edesz @mockingjet

About your issue, I had the same issue and I solved it using the python library in a pre_gen hook, check below, on this case is to create or not a Datadog_synth test that need the variables. I hope it is useful for you.

cookiecutter.json

{
  "project_name": "your_project_name",
  "test_creation": ["yes", "no"],
  "_copy_without_render": [
    ".github/workflows/*.yml"
  ]
}

pre_gen_project.py

import sys
import cookiecutter.prompt
'''
This pre_gen is to avoid to input tests variables if you don't want to create it
'''

if "{{ cookiecutter.test_creation }}" == "yes":
    cookiecutter.prompt.read_user_variable("test_name","your_synthetic_test_name")
    cookiecutter.prompt.read_user_variable("test_url","your_synthetic_test_url: Format http/https://url")
    cookiecutter.prompt.read_user_variable("test_contact","email_contact_here: Format @email")

else:
    """{{ cookiecutter.update(
        {
            "test_name": "",
            "test_url": "",
            "test_contact": ""
        }
    )}}"""

sys.exit(0)
2reactions
GianlucaFicarellicommented, Jun 21, 2022

@Chobito unless you do something with the returned value, calling cookiecutter.prompt.read_user_variable() is useless because it’s just calling click.prompt().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input prompt not returning to prior prompt after different failed ...
import module # Declaring the firstname lastname and raw_age type so that I can use global on them firstname = str lastname =...
Read more >
Restrict value entry in cell based on another cell value in Excel
How to restrict value entry/input in a cell based on another cell value in Excel? Supposing you need to restrict value entry in...
Read more >
Form Input Widgets Values Change based on Previous Inputs
During create data, I'm using a form where different input widgets are present for holding the end user data. The requirement is, prepopulate ......
Read more >
Restrict data input by using validation rules - Microsoft Support
Validations rules help you check data as it is added to your Access desktop database which improves accuracy and consistency of data entry....
Read more >
Solved: Initial input based on condition previous rows cel...
What I'm trying to achieve is based on a specific previous select is to auto populate (initial value) remaining questions based on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found