44"""
55import click
66
7- from .. import BaseFredAPIError
8- from .._util import generate_api_kwargs , serialize
7+ from .. import BaseFredAPIError , FredAPICategories
8+ from .._util import generate_api_kwargs , serialize , run_cli_callable , init_cli_context
99
1010__all__ = [
1111 "categories" ,
12+ "run_categories_cli" ,
1213]
1314
1415
1516@click .group ()
17+ @click .option ("--api-key" , type = click .STRING , required = False , help = "FRED API key." )
1618@click .pass_context
17- def categories (ctx ):
19+ def categories (ctx : click . Context , api_key : str ):
1820 """
1921 Categories CLI Namespace.
2022 """
21- pass
23+ init_cli_context ( ctx , api_key , FredAPICategories )
2224
2325
2426@categories .command ()
2527@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
2628@click .argument ("args" , nargs = - 1 )
2729@click .pass_context
28- def get_category (ctx , category_id : int , args : tuple ):
30+ def get_category (ctx : click . Context , category_id : int , args : tuple ):
2931 """Get a category."""
3032 try :
3133 click .echo (serialize (ctx .obj ["client" ].get_category (category_id , ** generate_api_kwargs (args ))))
@@ -37,7 +39,7 @@ def get_category(ctx, category_id: int, args: tuple):
3739@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
3840@click .argument ("args" , nargs = - 1 )
3941@click .pass_context
40- def get_category_children (ctx , category_id : int , args : tuple ):
42+ def get_category_children (ctx : click . Context , category_id : int , args : tuple ):
4143 """Get the child categories."""
4244 try :
4345 click .echo (serialize (ctx .obj ["client" ].get_category_children (category_id , ** generate_api_kwargs (args ))))
@@ -49,7 +51,7 @@ def get_category_children(ctx, category_id: int, args: tuple):
4951@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
5052@click .argument ("args" , nargs = - 1 )
5153@click .pass_context
52- def get_category_related (ctx , category_id : int , args : tuple ):
54+ def get_category_related (ctx : click . Context , category_id : int , args : tuple ):
5355 """Get related categories."""
5456 try :
5557 click .echo (serialize (ctx .obj ["client" ].get_category_related (category_id , ** generate_api_kwargs (args ))))
@@ -61,7 +63,7 @@ def get_category_related(ctx, category_id: int, args: tuple):
6163@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
6264@click .argument ("args" , nargs = - 1 )
6365@click .pass_context
64- def get_category_series (ctx , category_id : int , args : tuple ):
66+ def get_category_series (ctx : click . Context , category_id : int , args : tuple ):
6567 """Get series in a category."""
6668 try :
6769 click .echo (serialize (ctx .obj ["client" ].get_category_series (category_id , ** generate_api_kwargs (args ))))
@@ -73,7 +75,7 @@ def get_category_series(ctx, category_id: int, args: tuple):
7375@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
7476@click .argument ("args" , nargs = - 1 )
7577@click .pass_context
76- def get_category_tags (ctx , category_id : int , args : tuple ):
78+ def get_category_tags (ctx : click . Context , category_id : int , args : tuple ):
7779 """Get FRED tags for a category."""
7880 try :
7981 click .echo (serialize (ctx .obj ["client" ].get_category_tags (category_id , ** generate_api_kwargs (args ))))
@@ -86,11 +88,20 @@ def get_category_tags(ctx, category_id: int, args: tuple):
8688@click .option ("--tag-names" , "-t" , required = True , type = click .STRING , help = "Tag Names." )
8789@click .argument ("args" , nargs = - 1 )
8890@click .pass_context
89- def get_category_related_tags (ctx , category_id : int , tag_names : str , args : tuple ):
91+ def get_category_related_tags (ctx : click . Context , category_id : int , tag_names : str , args : tuple ):
9092 """Get related FRED tags for a category."""
9193 try :
9294 click .echo (
9395 serialize (ctx .obj ["client" ].get_category_related_tags (category_id , tag_names , ** generate_api_kwargs (args )))
9496 )
9597 except (ValueError , BaseFredAPIError ) as e :
9698 raise click .UsageError (click .style (e , fg = "red" ), ctx )
99+
100+
101+ def run_categories_cli ():
102+ """Run the CLI for Categories namespace."""
103+ run_cli_callable (cli_callable = categories )
104+
105+
106+ if __name__ == "__main__" :
107+ run_categories_cli ()
0 commit comments