66
77from robotcode .core .dataclasses import as_dict , as_json
88from robotcode .plugin import CommonConfig , pass_common_config
9-
10- from ...__version__ import __version__
11- from ..loader import find_project_root , get_config_files_from_folder , load_config_from_path
12- from ..model import RobotConfig
9+ from robotcode .robot .config .loader import find_project_root , get_config_files_from_folder , load_config_from_path
10+ from robotcode .robot .config .model import RobotConfig
1311
1412if sys .version_info >= (3 , 11 ):
1513 pass
2119 context_settings = {"help_option_names" : ["-h" , "--help" ], "auto_envvar_prefix" : "ROBOTCODE" },
2220 invoke_without_command = False ,
2321)
24- @click .version_option (version = __version__ , package_name = "robotcode.robot.config" , prog_name = "RobotCode Config" )
2522@click .pass_context
2623@pass_common_config
2724def config (
@@ -36,6 +33,40 @@ def config(
3633 return 0
3734
3835
36+ def print_config (config : RobotConfig , format : str , color : str ) -> int :
37+ text = None
38+ if format == "toml" :
39+ try :
40+ import tomli_w
41+
42+ text = tomli_w .dumps (as_dict (config , remove_defaults = True ))
43+ except ImportError :
44+ click .secho ("tomli-w is required to output toml." , fg = "red" , err = True )
45+
46+ format = "json"
47+
48+ if text is None :
49+ text = as_json (config , indent = True )
50+
51+ if color in ["auto" , "yes" ]:
52+ try :
53+ from rich .console import Console
54+ from rich .syntax import Syntax
55+
56+ Console ().print (Syntax (text , format , background_color = "default" ))
57+
58+ return 0
59+ except ImportError :
60+ if color == "yes" :
61+ click .secho ("rich is required to use colors." , fg = "red" , err = True )
62+ return 1
63+ pass
64+
65+ click .echo (text )
66+
67+ return 0
68+
69+
3970@config .command
4071@click .option (
4172 "-f" , "--format" , "format" , type = click .Choice (["json" , "toml" ]), default = "toml" , help = "Set the output format."
@@ -97,37 +128,3 @@ def show(
97128 return 1
98129
99130 return print_config (config , format , color )
100-
101-
102- def print_config (config : RobotConfig , format : str , color : str ) -> int :
103- text = None
104- if format == "toml" :
105- try :
106- import tomli_w
107-
108- text = tomli_w .dumps (as_dict (config , remove_defaults = True ))
109- except ImportError :
110- click .secho ("tomli-w is required to output toml." , fg = "red" , err = True )
111-
112- format = "json"
113-
114- if text is None :
115- text = as_json (config , indent = True )
116-
117- if color in ["auto" , "yes" ]:
118- try :
119- from rich .console import Console
120- from rich .syntax import Syntax
121-
122- Console ().print (Syntax (text , format , background_color = "default" ))
123-
124- return 0
125- except ImportError :
126- if color == "yes" :
127- click .secho ("rich is required to use colors." , fg = "red" , err = True )
128- return 1
129- pass
130-
131- click .echo (text )
132-
133- return 0
0 commit comments