29
29
@click .version_option (version = __version__ )
30
30
@click .pass_context
31
31
def 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 }
37
34
38
35
39
36
@cli .command ()
@@ -43,11 +40,11 @@ def cli(ctx: click.Context, file: Any, quote: Any, export: Any) -> None:
43
40
help = "The format in which to display the list. Default format is simple, "
44
41
"which displays name=value without quotes." )
45
42
def list (ctx : click .Context , format : bool ) -> None :
46
- ''' Display all the stored key/value.'''
43
+ """ Display all the stored key/value."""
47
44
file = ctx .obj ['FILE' ]
48
45
if not os .path .isfile (file ):
49
46
raise click .BadParameter (
50
- 'Path "%s " does not exist.' % ( file ) ,
47
+ f 'Path "{ file } " does not exist.' ,
51
48
ctx = ctx
52
49
)
53
50
dotenv_as_dict = dotenv_values (file )
@@ -60,21 +57,21 @@ def list(ctx: click.Context, format: bool) -> None:
60
57
if v is not None :
61
58
if format in ('export' , 'shell' ):
62
59
v = shlex .quote (v )
63
- click .echo ('%s%s=%s' % ( prefix , k , v ) )
60
+ click .echo (f' { prefix } { k } = { v } ' )
64
61
65
62
66
63
@cli .command ()
67
64
@click .pass_context
68
65
@click .argument ('key' , required = True )
69
66
@click .argument ('value' , required = True )
70
67
def set (ctx : click .Context , key : Any , value : Any ) -> None :
71
- ''' Store the given key/value.'''
68
+ """ Store the given key/value."""
72
69
file = ctx .obj ['FILE' ]
73
70
quote = ctx .obj ['QUOTE' ]
74
71
export = ctx .obj ['EXPORT' ]
75
72
success , key , value = set_key (file , key , value , quote , export )
76
73
if success :
77
- click .echo ('%s=%s' % ( key , value ) )
74
+ click .echo (f' { key } = { value } ' )
78
75
else :
79
76
exit (1 )
80
77
@@ -83,11 +80,11 @@ def set(ctx: click.Context, key: Any, value: Any) -> None:
83
80
@click .pass_context
84
81
@click .argument ('key' , required = True )
85
82
def get (ctx : click .Context , key : Any ) -> None :
86
- ''' Retrieve the value for the given key.'''
83
+ """ Retrieve the value for the given key."""
87
84
file = ctx .obj ['FILE' ]
88
85
if not os .path .isfile (file ):
89
86
raise click .BadParameter (
90
- 'Path "%s " does not exist.' % ( file ) ,
87
+ f 'Path "{ file } " does not exist.' ,
91
88
ctx = ctx
92
89
)
93
90
stored_value = get_key (file , key )
@@ -101,12 +98,12 @@ def get(ctx: click.Context, key: Any) -> None:
101
98
@click .pass_context
102
99
@click .argument ('key' , required = True )
103
100
def unset (ctx : click .Context , key : Any ) -> None :
104
- ''' Removes the given key.'''
101
+ """ Removes the given key."""
105
102
file = ctx .obj ['FILE' ]
106
103
quote = ctx .obj ['QUOTE' ]
107
104
success , key = unset_key (file , key , quote )
108
105
if success :
109
- click .echo ("Successfully removed %s" % key )
106
+ click .echo (f "Successfully removed { key } " )
110
107
else :
111
108
exit (1 )
112
109
@@ -124,7 +121,7 @@ def run(ctx: click.Context, override: bool, commandline: List[str]) -> None:
124
121
file = ctx .obj ['FILE' ]
125
122
if not os .path .isfile (file ):
126
123
raise click .BadParameter (
127
- 'Invalid value for \' -f\' "%s " does not exist.' % ( file ) ,
124
+ f 'Invalid value for \' -f\' "{ file } " does not exist.' ,
128
125
ctx = ctx
129
126
)
130
127
dotenv_as_dict = {
0 commit comments