2929@click .version_option (version = __version__ )
3030@click .pass_context
3131def cli (ctx : click .Context , file : Any , quote : Any , export : Any ) -> None :
32- '''This script is used to set, get or unset values from a .env file.'''
33- ctx .obj = {}
34- ctx .obj ['QUOTE' ] = quote
35- ctx .obj ['EXPORT' ] = export
36- ctx .obj ['FILE' ] = file
32+ """This script is used to set, get or unset values from a .env file."""
33+ ctx .obj = {'QUOTE' : quote , 'EXPORT' : export , 'FILE' : file }
3734
3835
3936@cli .command ()
@@ -43,11 +40,11 @@ def cli(ctx: click.Context, file: Any, quote: Any, export: Any) -> None:
4340 help = "The format in which to display the list. Default format is simple, "
4441 "which displays name=value without quotes." )
4542def list (ctx : click .Context , format : bool ) -> None :
46- ''' Display all the stored key/value.'''
43+ """ Display all the stored key/value."""
4744 file = ctx .obj ['FILE' ]
4845 if not os .path .isfile (file ):
4946 raise click .BadParameter (
50- 'Path "%s " does not exist.' % ( file ) ,
47+ f 'Path "{ file } " does not exist.' ,
5148 ctx = ctx
5249 )
5350 dotenv_as_dict = dotenv_values (file )
@@ -60,21 +57,21 @@ def list(ctx: click.Context, format: bool) -> None:
6057 if v is not None :
6158 if format in ('export' , 'shell' ):
6259 v = shlex .quote (v )
63- click .echo ('%s%s=%s' % ( prefix , k , v ) )
60+ click .echo (f' { prefix } { k } = { v } ' )
6461
6562
6663@cli .command ()
6764@click .pass_context
6865@click .argument ('key' , required = True )
6966@click .argument ('value' , required = True )
7067def set (ctx : click .Context , key : Any , value : Any ) -> None :
71- ''' Store the given key/value.'''
68+ """ Store the given key/value."""
7269 file = ctx .obj ['FILE' ]
7370 quote = ctx .obj ['QUOTE' ]
7471 export = ctx .obj ['EXPORT' ]
7572 success , key , value = set_key (file , key , value , quote , export )
7673 if success :
77- click .echo ('%s=%s' % ( key , value ) )
74+ click .echo (f' { key } = { value } ' )
7875 else :
7976 exit (1 )
8077
@@ -83,11 +80,11 @@ def set(ctx: click.Context, key: Any, value: Any) -> None:
8380@click .pass_context
8481@click .argument ('key' , required = True )
8582def get (ctx : click .Context , key : Any ) -> None :
86- ''' Retrieve the value for the given key.'''
83+ """ Retrieve the value for the given key."""
8784 file = ctx .obj ['FILE' ]
8885 if not os .path .isfile (file ):
8986 raise click .BadParameter (
90- 'Path "%s " does not exist.' % ( file ) ,
87+ f 'Path "{ file } " does not exist.' ,
9188 ctx = ctx
9289 )
9390 stored_value = get_key (file , key )
@@ -101,12 +98,12 @@ def get(ctx: click.Context, key: Any) -> None:
10198@click .pass_context
10299@click .argument ('key' , required = True )
103100def unset (ctx : click .Context , key : Any ) -> None :
104- ''' Removes the given key.'''
101+ """ Removes the given key."""
105102 file = ctx .obj ['FILE' ]
106103 quote = ctx .obj ['QUOTE' ]
107104 success , key = unset_key (file , key , quote )
108105 if success :
109- click .echo ("Successfully removed %s" % key )
106+ click .echo (f "Successfully removed { key } " )
110107 else :
111108 exit (1 )
112109
@@ -124,7 +121,7 @@ def run(ctx: click.Context, override: bool, commandline: List[str]) -> None:
124121 file = ctx .obj ['FILE' ]
125122 if not os .path .isfile (file ):
126123 raise click .BadParameter (
127- 'Invalid value for \' -f\' "%s " does not exist.' % ( file ) ,
124+ f 'Invalid value for \' -f\' "{ file } " does not exist.' ,
128125 ctx = ctx
129126 )
130127 dotenv_as_dict = {
0 commit comments