@@ -50,6 +50,8 @@ def parse_args(args: List[str]) -> argparse.Namespace:
5050 parser_config_set = subparsers_config .add_parser ("set" )
5151 parser_config_set .add_argument ("name" )
5252 parser_config_set .add_argument ("value" )
53+ parser_config_unset = subparsers_config .add_parser ("unset" )
54+ parser_config_unset .add_argument ("name" )
5355 parser_doc = subparsers .add_parser (
5456 "doctor" , help = "Check that the system meets requirements"
5557 )
@@ -129,6 +131,8 @@ class Config(dict):
129131 __slots__ = ["user_obj" , "user_path" ]
130132
131133 def load (self , config_path : Path | None = None ):
134+ args = self .get ("args" )
135+ self .clear ()
132136 parsed = tomlkit .parse ((Path (__file__ ).parent / "config.toml" ).read_text ())
133137 self .update (parsed )
134138 if config_path :
@@ -140,6 +144,8 @@ def load(self, config_path: Path | None = None):
140144 raise OSError (f"Config file at { self .user_path } not found!" )
141145 else :
142146 self .user_obj = {}
147+ if args :
148+ self ["args" ] = args
143149
144150 def dump (self ):
145151 return tomlkit .dumps (self )
@@ -182,6 +188,24 @@ def set_value(self, name: str, value: str) -> None:
182188 self .user_path .write_text (tomlkit .dumps (self .user_obj ).strip ())
183189 i += 1
184190
191+ def unset_value (self , name : str ) -> None :
192+ path = name .split ("." )
193+ obj = self .user_obj
194+ i = 0
195+ last_index = len (path ) - 1
196+ while i <= last_index :
197+ if i < last_index :
198+ if path [i ] not in obj :
199+ break
200+ obj = obj [path [i ]]
201+ elif i == last_index :
202+ obj .pop (path [i ])
203+ self .update (self .user_obj )
204+ self .user_path .parent .mkdir (exist_ok = True )
205+ self .user_path .write_text (tomlkit .dumps (self .user_obj ).strip ())
206+ i += 1
207+ self .load (self .user_path )
208+
185209
186210config = Config ()
187211config .load ()
0 commit comments