Bird
0
0

Why does this Flask CLI command raise an error?

medium📝 Debug Q7 of 15
Flask - Ecosystem and Patterns
Why does this Flask CLI command raise an error?
from flask import Flask
app = Flask(__name__)

@app.cli.command()
@click.option('--count', default=1)
def repeat(count):
    for _ in range(count):
        print('Repeat')

Command run: flask repeat --count five
AThe option 'count' expects an integer but received a string
BThe command name 'repeat' is invalid
CMissing @click.argument decorator
DFlask app instance is not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Analyze option type

    The --count option expects an integer by default.
  2. Step 2: Check passed value

    Passing 'five' (a string) causes a type error because it cannot convert to int.
  3. Final Answer:

    The option 'count' expects an integer but received a string -> Option A
  4. Quick Check:

    Option types must match passed values [OK]
Quick Trick: Pass correct types for click options [OK]
Common Mistakes:
MISTAKES
  • Passing strings to int options
  • Ignoring type errors
  • Assuming all options accept strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes