feat: proper config method
This commit is contained in:
parent
38768737b1
commit
dba2a2b70c
22
README.md
22
README.md
@ -1,3 +1,23 @@
|
|||||||
# Git Time Tracking
|
# Git Time Tracking
|
||||||
|
|
||||||
This is a tool, allowing you to view the commits you have made in a set of repositories. This is useful if you need to write down your times for work.
|
This is a tool, allowing you to view the commits you have made in a set of repositories. This is useful if you need to write down your times for work.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
You can install the program by using pip:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install git-time-tracking
|
||||||
|
```
|
||||||
|
|
||||||
|
> Make sure nano is installed on your system, as it is used for editing the config file.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
You can see all the cli options by running:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git_time_tracking --help
|
||||||
|
```
|
||||||
|
|
||||||
|
The first time running the program, you will be thrown into `nano` (has to be installed). Here you can specify the repositories you want to track, and some other settings.
|
||||||
|
@ -1,20 +1,30 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from .utils import SETTINGS, console
|
from .utils import (CONFIG_PATH, SETTINGS, SETTINGS_EXISTED, console,
|
||||||
|
load_config, save_config)
|
||||||
|
|
||||||
|
|
||||||
|
def configure():
|
||||||
|
save_config()
|
||||||
|
subprocess.call(['nano', str(CONFIG_PATH)])
|
||||||
|
load_config()
|
||||||
|
|
||||||
GIT_COMMAND = """
|
|
||||||
git log "
|
|
||||||
"""
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# get the user input
|
# get the user input
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("date", help="The date to get the logs for")
|
parser.add_argument("--date", help="The date to get the logs for", nargs="?", const=None)
|
||||||
|
parser.add_argument("--author", help="The author to get the logs for", nargs="?", const=None)
|
||||||
|
parser.add_argument("--config", action=argparse.BooleanOptionalAction, help="Configure the settings")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
parsed_date = raw_date = args.date.replace("date=", "")
|
if not SETTINGS_EXISTED or args.config:
|
||||||
|
configure()
|
||||||
|
|
||||||
|
parsed_date = raw_date = args.date.replace("date=", "") if args.date is not None else datetime.datetime.now().strftime(SETTINGS["date_format"])
|
||||||
try:
|
try:
|
||||||
date = datetime.datetime.strptime(raw_date, SETTINGS["date_format"]).date()
|
date = datetime.datetime.strptime(raw_date, SETTINGS["date_format"]).date()
|
||||||
parsed_date = date.strftime("%Y-%m-%d")
|
parsed_date = date.strftime("%Y-%m-%d")
|
||||||
@ -24,7 +34,7 @@ def main():
|
|||||||
if SETTINGS["git_author"] is None:
|
if SETTINGS["git_author"] is None:
|
||||||
SETTINGS["git_author"] = console.input("Whats your name? ").strip()
|
SETTINGS["git_author"] = console.input("Whats your name? ").strip()
|
||||||
|
|
||||||
parsed_author = SETTINGS["git_author"].replace("'", "")
|
parsed_author = (args.author or SETTINGS["git_author"]).replace("'", "")
|
||||||
pretty_author = parsed_author if not SETTINGS["censor_author"] else "*" * len(parsed_author)
|
pretty_author = parsed_author if not SETTINGS["censor_author"] else "*" * len(parsed_author)
|
||||||
|
|
||||||
console.print("date:\t", parsed_date, style="bold")
|
console.print("date:\t", parsed_date, style="bold")
|
||||||
|
@ -9,6 +9,7 @@ from .__about__ import __name__
|
|||||||
|
|
||||||
console: Console = Console()
|
console: Console = Console()
|
||||||
|
|
||||||
|
SETTINGS_EXISTED = False
|
||||||
CONFIG_PATH = Path.home() / ".config" / __name__ / "config.toml"
|
CONFIG_PATH = Path.home() / ".config" / __name__ / "config.toml"
|
||||||
SETTINGS = {
|
SETTINGS = {
|
||||||
"git_directories": [],
|
"git_directories": [],
|
||||||
@ -18,7 +19,10 @@ SETTINGS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
|
global SETTINGS_EXISTED
|
||||||
|
|
||||||
if CONFIG_PATH.exists():
|
if CONFIG_PATH.exists():
|
||||||
|
SETTINGS_EXISTED = True
|
||||||
with CONFIG_PATH.open("r", encoding="utf-8") as f:
|
with CONFIG_PATH.open("r", encoding="utf-8") as f:
|
||||||
config = toml.load(f)
|
config = toml.load(f)
|
||||||
SETTINGS.update(config)
|
SETTINGS.update(config)
|
||||||
|
Loading…
Reference in New Issue
Block a user