88 "offset" : 4 ,
99 }
1010
11+
1112class Cli :
1213 # pylint: disable=too-few-public-methods
1314 """ command-line-interface """
1415
1516 def __init__ (self ):
16- """ initialize the CLI """
17+ """ Initialize the CLI. """
1718 parser = argparse .ArgumentParser (
1819 description = "Format YAML files" ,
1920 formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
@@ -137,7 +138,7 @@ def represent_none(self, _data):
137138 self .content = list ({})
138139
139140 def format (self , path = None ):
140- """ Read file and write it out to same path """
141+ """ Read file and write it out to same path. """
141142 if not path :
142143 path = self .path
143144 print (path , end = "" )
@@ -146,7 +147,7 @@ def format(self, path=None):
146147 print (" Done" )
147148
148149 def parse_file (self , path = None ):
149- """ Read the file """
150+ """ Read the file. """
150151 if not path :
151152 path = self .path
152153 try :
@@ -156,7 +157,7 @@ def parse_file(self, path=None):
156157 self .fail (f"Unable to read { path } " )
157158
158159 def write_file (self , path = None ):
159- """ Write the file """
160+ """ Write the file. """
160161 if not path :
161162 path = self .path
162163 try :
@@ -167,28 +168,26 @@ def write_file(self, path=None):
167168
168169 @staticmethod
169170 def fail (msg ):
170- """ Abort """
171+ """ Abort. """
171172 sys .stderr .write (msg )
172173 sys .exit (1 )
173-
174174
175175
176176def main ():
177- ARGS = Cli ().parser .parse_args ()
178- FORMATTER = Formatter (
179- mapping = ARGS .mapping ,
180- sequence = ARGS .sequence ,
181- offset = ARGS .offset ,
182- colons = ARGS .colons ,
183- width = ARGS .width ,
184- preserve_quotes = ARGS .preserve_quotes ,
185- preserve_null = ARGS .preserve_null ,
186- explicit_start = ARGS .explicit_start ,
187- explicit_end = ARGS .explicit_end
177+ args = Cli ().parser .parse_args ()
178+ formatter = Formatter (
179+ mapping = args .mapping ,
180+ sequence = args .sequence ,
181+ offset = args .offset ,
182+ colons = args .colons ,
183+ width = args .width ,
184+ preserve_quotes = args .preserve_quotes ,
185+ preserve_null = args .preserve_null ,
186+ explicit_start = args .explicit_start ,
187+ explicit_end = args .explicit_end
188188 )
189- for file_name in ARGS .file_names :
190- FORMATTER .format (file_name )
191-
189+ for file_name in args .file_names :
190+ formatter .format (file_name )
192191
193192
194193if __name__ == "__main__" :
0 commit comments