4
4
"""
5
5
import click
6
6
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
9
9
10
10
__all__ = [
11
11
"categories" ,
12
+ "run_categories_cli" ,
12
13
]
13
14
14
15
15
16
@click .group ()
17
+ @click .option ("--api-key" , type = click .STRING , required = False , help = "FRED API key." )
16
18
@click .pass_context
17
- def categories (ctx ):
19
+ def categories (ctx : click . Context , api_key : str ):
18
20
"""
19
21
Categories CLI Namespace.
20
22
"""
21
- pass
23
+ init_cli_context ( ctx , api_key , FredAPICategories )
22
24
23
25
24
26
@categories .command ()
25
27
@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
26
28
@click .argument ("args" , nargs = - 1 )
27
29
@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 ):
29
31
"""Get a category."""
30
32
try :
31
33
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):
37
39
@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
38
40
@click .argument ("args" , nargs = - 1 )
39
41
@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 ):
41
43
"""Get the child categories."""
42
44
try :
43
45
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):
49
51
@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
50
52
@click .argument ("args" , nargs = - 1 )
51
53
@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 ):
53
55
"""Get related categories."""
54
56
try :
55
57
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):
61
63
@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
62
64
@click .argument ("args" , nargs = - 1 )
63
65
@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 ):
65
67
"""Get series in a category."""
66
68
try :
67
69
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):
73
75
@click .option ("--category-id" , "-i" , required = True , type = click .STRING , help = "Category ID." )
74
76
@click .argument ("args" , nargs = - 1 )
75
77
@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 ):
77
79
"""Get FRED tags for a category."""
78
80
try :
79
81
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):
86
88
@click .option ("--tag-names" , "-t" , required = True , type = click .STRING , help = "Tag Names." )
87
89
@click .argument ("args" , nargs = - 1 )
88
90
@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 ):
90
92
"""Get related FRED tags for a category."""
91
93
try :
92
94
click .echo (
93
95
serialize (ctx .obj ["client" ].get_category_related_tags (category_id , tag_names , ** generate_api_kwargs (args )))
94
96
)
95
97
except (ValueError , BaseFredAPIError ) as e :
96
98
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