6
6
from PyTM import __version__
7
7
import os
8
8
import datetime
9
- from PyTM .core .data_handler import init_data , load_data
9
+ from PyTM .core .data_handler import init_data , load_data , save_data
10
10
from PyTM .settings import data_folder , data_filepath , state_filepath , CURRENT_PROJECT , CURRENT_TASK
11
11
from PyTM .console import console
12
12
from rich .table import Table
13
+ from rich .prompt import Prompt
14
+ from rich .prompt import Confirm
13
15
def greet ():
14
16
"""
15
17
shows Greeting Texts
@@ -57,9 +59,9 @@ def cli():
57
59
@click .command ()
58
60
def init ():
59
61
"""
60
- Initialize the pytm data store.
62
+ - initializes the pytm data store.
61
63
"""
62
- console .print ("[green on white]Initializing pytm-data." )
64
+ console .print ("[green on white]Initializing pytm-data.\n " )
63
65
try :
64
66
os .makedirs (data_folder )
65
67
console .print (f"Created data folder: { data_folder } " )
@@ -77,11 +79,12 @@ def init():
77
79
init_data (state_filepath , {CURRENT_PROJECT : "" , CURRENT_TASK : "" })
78
80
console .print (f"Created state file: { state_filepath } " )
79
81
console .print ("Done." )
82
+ console .print ("\n [bold blue i on white]You also might want to run: `pytm config user` to configure default user data.[/bold blue i on white]" )
80
83
81
84
@click .command ()
82
85
def show ():
83
86
"""
84
- shows list of projects and status
87
+ - shows list of projects and status
85
88
"""
86
89
data = load_data ()
87
90
table = Table ()
@@ -92,10 +95,60 @@ def show():
92
95
table .add_row (key , f'{ datetime .datetime .fromisoformat (value ['created_at' ]).strftime ("%Y, %B, %d, %H:%M:%S %p" )} ' , value ['status' ])
93
96
console .print (table )
94
97
98
+ @click .group ()
99
+ def config ():
100
+ """
101
+ - pytm sub-commands for configuration.
102
+ """
103
+ ...
104
+
105
+ @config .command ()
106
+ def user ():
107
+ """
108
+ - config default user.
109
+ """
110
+ state = load_data (state_filepath )
111
+ current_user = {}
112
+ if state .get ("config" ):
113
+ current_user = state .get ("config" ).get ("user" , {})
114
+ else :
115
+ state ['config' ] = dict ()
116
+ current_user ["name" ] = Prompt .ask ("Name" , default = current_user .get ("name" , "" ))
117
+ current_user ["email" ] = Prompt .ask ("Email" , default = current_user .get ("email" , "" ))
118
+ current_user ["phone" ] = Prompt .ask ("Phone" , default = current_user .get ("phone" , "" ))
119
+ current_user ["address" ] = Prompt .ask ("Address" , default = current_user .get ("address" , "" ))
120
+ current_user ["website" ] = Prompt .ask ("Website" , default = current_user .get ("website" , "" ))
121
+ current_user ["hourly_rate" ] = Prompt .ask ("Hourly rate in USD" , default = current_user .get ("hourly_rate" , "" ))
122
+ state ['config' ]['user' ] = current_user
123
+ save_data (state , state_filepath )
124
+ console .print ("\n [green]Default user info updated." )
125
+
126
+ @config .command (name = "project" )
127
+ @click .argument ("project_name" )
128
+ def config_project (project_name ):
129
+ """
130
+ - config project meta data.
131
+ """
132
+ data = load_data ()
133
+ if data .get (project_name ):
134
+ data [project_name ]['meta' ] = data .get (project_name ).get ("meta" , {})
135
+ data [project_name ]['meta' ]["title" ] = Prompt .ask ("Project Title" , default = data [project_name ]['meta' ].get ("title" , "" ))
136
+ data [project_name ]['meta' ]["billable" ] = Confirm .ask ("Billable?" , default = data [project_name ]['meta' ].get ("billable" , True ))
137
+ data [project_name ]['meta' ]["client_name" ] = Prompt .ask ("Client Name" , default = data [project_name ]['meta' ].get ("client_name" , "" ))
138
+ data [project_name ]['meta' ]["client_email" ] = Prompt .ask ("Client Email" , default = data [project_name ]['meta' ].get ("client_email" , "" ))
139
+ data [project_name ]['meta' ]["client_phone" ] = Prompt .ask ("Client Phone" , default = data [project_name ]['meta' ].get ("client_phone" , "" ))
140
+ data [project_name ]['meta' ]["client_address" ] = Prompt .ask ("Client Address" , default = data [project_name ]['meta' ].get ("client_address" , "" ))
141
+ data [project_name ]['meta' ]["client_website" ] = Prompt .ask ("Client Website" , default = data [project_name ]['meta' ].get ("client_website" , "" ))
142
+ else :
143
+ console .print (f"[bold red] Project { project_name } doesn't exist." )
144
+ save_data (data )
145
+ console .print ("\n [green]Project Meta data updated." )
146
+
95
147
cli .add_command (init )
96
148
cli .add_command (project )
97
149
cli .add_command (task )
98
150
cli .add_command (show )
151
+ cli .add_command (config )
99
152
100
153
if __name__ == "__main__" :
101
154
cli ()
0 commit comments