Skip to content

Commit

Permalink
Adding legl-dev code
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-bell committed Feb 16, 2022
1 parent 43ab100 commit a6980fc
Show file tree
Hide file tree
Showing 7 changed files with 771 additions and 1 deletion.
189 changes: 188 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,188 @@
# legl-dev
# `legl-dev`

**Usage**:

```console
$ legl-dev [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
* `--help`: Show this message and exit.

**Commands**:

* `build`: Rebuild the local enviroment
* `cypress`: Open Cpyress e2e tests
* `factories`: Clean out and create new factories
* `format`: Format the code with black and prettier
* `gitclean`: Cleans out git branches
* `jstest`: Run JS unit tests
* `migrate`: Create and run migrations
* `pytest`: Run the local pytest unit tests
* `start`: Start the dev enviroment
* `update`: Update dependancies

## `legl-dev build`

Rebuild the local enviroment

**Usage**:

```console
$ legl-dev build [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--create-db / --no-create-db`: Drop the database and create a fresh one [default: False]
* `--help`: Show this message and exit.

## `legl-dev cypress`

Open Cpyress e2e tests

**Usage**:

```console
$ legl-dev cypress [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]
* `--help`: Show this message and exit.

## `legl-dev factories`

Clean out and create new factories

**Usage**:

```console
$ legl-dev factories [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--help`: Show this message and exit.

## `legl-dev format`

Format the code with black and prettier

**Usage**:

```console
$ legl-dev format [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--push / --no-push`: Also push the changes to the repo [default: False]
* `--help`: Show this message and exit.

## `legl-dev gitclean`

Cleans out git branches

**Usage**:

```console
$ legl-dev gitclean [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--help`: Show this message and exit.

## `legl-dev jstest`

Run JS unit tests

**Usage**:

```console
$ legl-dev jstest [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]
* `--help`: Show this message and exit.

## `legl-dev migrate`

Create and run migrations

**Usage**:

```console
$ legl-dev migrate [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--merge / --no-merge`: Run a migration merge first [default: False]
* `--help`: Show this message and exit.

## `legl-dev pytest`

Run the local pytest unit tests

**Usage**:

```console
$ legl-dev pytest [OPTIONS] [PATH]
```

**Arguments**:

* `[PATH]`: path for specific test in the format "<file path>::<class name>::<function name>" [default: ]

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--full-diff / --no-full-diff`: Show full diff in errors [default: False]
* `--create-db / --no-create-db`: Recreates the test database [default: False]
* `--last-failed / --no-last-failed`: Run the last failed tests [default: False]
* `--warnings / --no-warnings`: Toggle warnings in output [default: True]
* `--gui / --no-gui`: Toggle the output gui [default: True]
* `--help`: Show this message and exit.

## `legl-dev start`

Start the dev enviroment

**Usage**:

```console
$ legl-dev start [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]
* `--help`: Show this message and exit.

## `legl-dev update`

Update dependancies

**Usage**:

```console
$ legl-dev update [OPTIONS]
```

**Options**:

* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]
* `--help`: Show this message and exit.
Empty file added legl_dev/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions legl_dev/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from datetime import datetime
from os import mkdir
from subprocess import CalledProcessError, run
from threading import Thread
from typing import Union

from yaspin import yaspin


class Command:
def __init__(
self, command: str, desc: str, log_file: str, verbose: bool = False, shell: bool = False,
) -> None:
self.command = command
self.desc = desc
self.log_file = log_file
self.verbose = verbose
self.shell = shell

def run(self) -> None:
if self.verbose:
run(
self.command if self.shell else self.command.split(),
universal_newlines=True,
shell=self.shell,
)
return
with yaspin(text=f"{self.desc}", color="yellow") as spinner:
try:
try:
mkdir("logs/")
except FileExistsError:
pass
with open(f"logs/{self.log_file}.log", "w") as outfile:
start_time = datetime.now()
run(
self.command if self.shell else self.command.split(),
stdout=outfile,
stderr=outfile,
shell=self.shell,
)
run_time = datetime.now() - start_time
with open(f"logs/{self.log_file}.log", "r") as outfile:
if "error:" in outfile.read().lower():
spinner.text = f"{self.desc} - \033[93mWarning\033[0m please check: \33[34mlogs/{self.log_file}.log\033[4m"
spinner.fail("⚠")
else:
spinner.text = f"{self.desc} {' ' * (45-len(self.desc))}\033[93m[{str(run_time)[:-5]}]\033[0m"
spinner.color = "green"
spinner.ok("✔")
except CalledProcessError:
spinner.color = "red"
spinner.fail("✖")


class Steps:
def __init__(self, steps: list = [], concurrent: bool = False) -> None:
self.steps = steps
self.concurrent = concurrent

def add(self, steps: Union[list, Command]) -> None:
try:
self.steps += steps
except TypeError:
self.steps += [steps]

def run(self) -> None:
for step in self.steps:
if self.concurrent:
Thread(target=step.run).start()
else:
step.run()
Loading

0 comments on commit a6980fc

Please sign in to comment.