hfmt-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hfmt_cli-0.1.0/LICENSE +28 -0
- hfmt_cli-0.1.0/PKG-INFO +121 -0
- hfmt_cli-0.1.0/README.md +81 -0
- hfmt_cli-0.1.0/pyproject.toml +16 -0
- hfmt_cli-0.1.0/setup.cfg +4 -0
- hfmt_cli-0.1.0/src/hfmt/__init__.py +2 -0
- hfmt_cli-0.1.0/src/hfmt/cli.py +278 -0
- hfmt_cli-0.1.0/src/hfmt_cli.egg-info/PKG-INFO +121 -0
- hfmt_cli-0.1.0/src/hfmt_cli.egg-info/SOURCES.txt +10 -0
- hfmt_cli-0.1.0/src/hfmt_cli.egg-info/dependency_links.txt +1 -0
- hfmt_cli-0.1.0/src/hfmt_cli.egg-info/entry_points.txt +2 -0
- hfmt_cli-0.1.0/src/hfmt_cli.egg-info/top_level.txt +1 -0
hfmt_cli-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Bogdan Pricope
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
hfmt_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hfmt-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple CLI utility for generating formatted text headers with borders and boxes.
|
|
5
|
+
Author: Bogdan Pricope
|
|
6
|
+
License: BSD 3-Clause License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025, Bogdan Pricope
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions are met:
|
|
12
|
+
|
|
13
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
14
|
+
list of conditions and the following disclaimer.
|
|
15
|
+
|
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
|
18
|
+
and/or other materials provided with the distribution.
|
|
19
|
+
|
|
20
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
21
|
+
contributors may be used to endorse or promote products derived from
|
|
22
|
+
this software without specific prior written permission.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
25
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
26
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
32
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
+
|
|
35
|
+
Keywords: cli,formatting,headers,borders,boxes,ascii,unicode
|
|
36
|
+
Requires-Python: >=3.9
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# hfmt-cli
|
|
42
|
+
|
|
43
|
+
<p align="left">
|
|
44
|
+
<img src="https://badges.fw-web.space/github/license/BogdanPri/header-cli?style=flat-square">
|
|
45
|
+
<img src="https://badges.fw-web.space/github/languages/code-size/BogdanPri/header-cli?style=flat-square">
|
|
46
|
+
<img alt="GitHub top language" src="https://badges.fw-web.space/github/languages/top/BogdanPri/header-cli?style=flat-square">
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
A simple CLI utility for generating formatted text headers with borders and boxes.
|
|
50
|
+
|
|
51
|
+
## 📦 Requirements
|
|
52
|
+
|
|
53
|
+
* Python >= 3.9
|
|
54
|
+
|
|
55
|
+
## 🛠 Usage
|
|
56
|
+
|
|
57
|
+
Run with a positional argument:
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
$ hfmt "project title"
|
|
61
|
+
################################## project title ###################################
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Run with flags:
|
|
66
|
+
```console
|
|
67
|
+
$ hfmt --head "build complete" --style multi --char "=" --width 60 --upper --align left
|
|
68
|
+
============================================================
|
|
69
|
+
= BUILD COMPLETE
|
|
70
|
+
============================================================
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```console
|
|
74
|
+
$ hfmt --border-only --width 50
|
|
75
|
+
##################################################
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Run with box mode:
|
|
79
|
+
```console
|
|
80
|
+
$ hfmt --title --width auto --box double "welcome back"
|
|
81
|
+
╔══════════════╗
|
|
82
|
+
║ Welcome Back ║
|
|
83
|
+
╚══════════════╝
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### ⚙️ Options
|
|
87
|
+
|
|
88
|
+
`hfmt-cli` supports the following value flags:
|
|
89
|
+
|
|
90
|
+
| Flag | Description | Default |
|
|
91
|
+
|------|-------------|---------|
|
|
92
|
+
| `head` (positional) | Header text | — |
|
|
93
|
+
| `-H, --head` | Header text (alternative flag form) | — |
|
|
94
|
+
| `-s, --style` | Border style (`single`, `multi`) | `single` |
|
|
95
|
+
| `-c, --char` | Character to use for the border | `#` |
|
|
96
|
+
| `-w, --width` | Width of the rows | `84` or `auto` |
|
|
97
|
+
| `-a, --align` | Header justification | `center` or `left` |
|
|
98
|
+
| `-b, --box` | Surround header by a box (overrides other flags) | `none` |
|
|
99
|
+
|
|
100
|
+
`hfmt-cli` supports the following value toggles:
|
|
101
|
+
|
|
102
|
+
| Toggle | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `-U, --upper` | Converts header to "UPPER_CASE" |
|
|
105
|
+
| `-L, --lower` | Converts header to "lower_case" |
|
|
106
|
+
| `-T, --title` | Converts header to "Title_Case" |
|
|
107
|
+
| `-S, --swapcase` | Converts header to "sWAP_cASE" |
|
|
108
|
+
| `--border-only` | Returns only a border of characters with no header |
|
|
109
|
+
|
|
110
|
+
## 🚀 Installation
|
|
111
|
+
|
|
112
|
+
Clone the git repo:
|
|
113
|
+
```console
|
|
114
|
+
git clone https://www.github.com/BogdanPri/hfmt-cli.git
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Install via `pip`:
|
|
118
|
+
```console
|
|
119
|
+
cd hfmt-cli
|
|
120
|
+
pip install -e .
|
|
121
|
+
```
|
hfmt_cli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# hfmt-cli
|
|
2
|
+
|
|
3
|
+
<p align="left">
|
|
4
|
+
<img src="https://badges.fw-web.space/github/license/BogdanPri/header-cli?style=flat-square">
|
|
5
|
+
<img src="https://badges.fw-web.space/github/languages/code-size/BogdanPri/header-cli?style=flat-square">
|
|
6
|
+
<img alt="GitHub top language" src="https://badges.fw-web.space/github/languages/top/BogdanPri/header-cli?style=flat-square">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
A simple CLI utility for generating formatted text headers with borders and boxes.
|
|
10
|
+
|
|
11
|
+
## 📦 Requirements
|
|
12
|
+
|
|
13
|
+
* Python >= 3.9
|
|
14
|
+
|
|
15
|
+
## 🛠 Usage
|
|
16
|
+
|
|
17
|
+
Run with a positional argument:
|
|
18
|
+
|
|
19
|
+
```console
|
|
20
|
+
$ hfmt "project title"
|
|
21
|
+
################################## project title ###################################
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Run with flags:
|
|
26
|
+
```console
|
|
27
|
+
$ hfmt --head "build complete" --style multi --char "=" --width 60 --upper --align left
|
|
28
|
+
============================================================
|
|
29
|
+
= BUILD COMPLETE
|
|
30
|
+
============================================================
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```console
|
|
34
|
+
$ hfmt --border-only --width 50
|
|
35
|
+
##################################################
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run with box mode:
|
|
39
|
+
```console
|
|
40
|
+
$ hfmt --title --width auto --box double "welcome back"
|
|
41
|
+
╔══════════════╗
|
|
42
|
+
║ Welcome Back ║
|
|
43
|
+
╚══════════════╝
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### ⚙️ Options
|
|
47
|
+
|
|
48
|
+
`hfmt-cli` supports the following value flags:
|
|
49
|
+
|
|
50
|
+
| Flag | Description | Default |
|
|
51
|
+
|------|-------------|---------|
|
|
52
|
+
| `head` (positional) | Header text | — |
|
|
53
|
+
| `-H, --head` | Header text (alternative flag form) | — |
|
|
54
|
+
| `-s, --style` | Border style (`single`, `multi`) | `single` |
|
|
55
|
+
| `-c, --char` | Character to use for the border | `#` |
|
|
56
|
+
| `-w, --width` | Width of the rows | `84` or `auto` |
|
|
57
|
+
| `-a, --align` | Header justification | `center` or `left` |
|
|
58
|
+
| `-b, --box` | Surround header by a box (overrides other flags) | `none` |
|
|
59
|
+
|
|
60
|
+
`hfmt-cli` supports the following value toggles:
|
|
61
|
+
|
|
62
|
+
| Toggle | Description |
|
|
63
|
+
|--------|-------------|
|
|
64
|
+
| `-U, --upper` | Converts header to "UPPER_CASE" |
|
|
65
|
+
| `-L, --lower` | Converts header to "lower_case" |
|
|
66
|
+
| `-T, --title` | Converts header to "Title_Case" |
|
|
67
|
+
| `-S, --swapcase` | Converts header to "sWAP_cASE" |
|
|
68
|
+
| `--border-only` | Returns only a border of characters with no header |
|
|
69
|
+
|
|
70
|
+
## 🚀 Installation
|
|
71
|
+
|
|
72
|
+
Clone the git repo:
|
|
73
|
+
```console
|
|
74
|
+
git clone https://www.github.com/BogdanPri/hfmt-cli.git
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Install via `pip`:
|
|
78
|
+
```console
|
|
79
|
+
cd hfmt-cli
|
|
80
|
+
pip install -e .
|
|
81
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hfmt-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A simple CLI utility for generating formatted text headers with borders and boxes."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [{ name = "Bogdan Pricope"}]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
keywords = ["cli", "formatting", "headers", "borders", "boxes", "ascii", "unicode"]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
hfmt = "hfmt.cli:main"
|
hfmt_cli-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
####################################################################################
|
|
4
|
+
# - COPYRIGHT -
|
|
5
|
+
####################################################################################
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
hfmt-cli — A simple CLI utility for generating formatted text headers.
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Bogdan Pricope
|
|
11
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
####################################################################################
|
|
15
|
+
# - MODULES -
|
|
16
|
+
####################################################################################
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import sys
|
|
20
|
+
import warnings
|
|
21
|
+
|
|
22
|
+
####################################################################################
|
|
23
|
+
# - FUNCTIONS -
|
|
24
|
+
####################################################################################
|
|
25
|
+
|
|
26
|
+
def hfmt(head: str, args) -> str:
|
|
27
|
+
""" This function takes a string and formats it as a header, using the
|
|
28
|
+
specified style, width and character."""
|
|
29
|
+
|
|
30
|
+
########################### - BOXED HEADER FORMAT - ############################
|
|
31
|
+
|
|
32
|
+
formatted_head: str = f" {head} "
|
|
33
|
+
char_len: int = len(args.char)
|
|
34
|
+
|
|
35
|
+
if char_len > 1:
|
|
36
|
+
char0: str = args.char[0]
|
|
37
|
+
char1: str = args.char[-1]
|
|
38
|
+
if char_len > 2:
|
|
39
|
+
chars: str = args.char[1:-1]
|
|
40
|
+
else:
|
|
41
|
+
chars: str = ""
|
|
42
|
+
else:
|
|
43
|
+
char0: str = args.char
|
|
44
|
+
char1: str = args.char
|
|
45
|
+
chars: str = ""
|
|
46
|
+
|
|
47
|
+
width: int = get_width(args.width, args.box, args.style, char_len, formatted_head)
|
|
48
|
+
align: str = get_align(args.align, args.box, args.style)
|
|
49
|
+
|
|
50
|
+
border: str = char1*width if char_len == 1 else char0 + char1*(width-2) + char0
|
|
51
|
+
|
|
52
|
+
if args.border_only:
|
|
53
|
+
return border
|
|
54
|
+
|
|
55
|
+
if args.box != 'none':
|
|
56
|
+
return draw_boxed(formatted_head, args.box, width, align)
|
|
57
|
+
|
|
58
|
+
############################ - CHAR HEADER FORMAT - ############################
|
|
59
|
+
|
|
60
|
+
if args.style == 'multi':
|
|
61
|
+
return (
|
|
62
|
+
f"{border}\n"
|
|
63
|
+
f"{char0*char_len}{formatted_head:{align}{width-char_len}}\n"
|
|
64
|
+
f"{border}"
|
|
65
|
+
)
|
|
66
|
+
if args.style == 'boxed':
|
|
67
|
+
return (
|
|
68
|
+
f"{border}\n{char0}{char1 * (char_len-1)}"
|
|
69
|
+
f"{formatted_head:{align}{width-2*char_len}}"
|
|
70
|
+
f"{char1 * (char_len-1)}{char0}\n{border}"
|
|
71
|
+
)
|
|
72
|
+
return f"{char0}{chars}{formatted_head:{char1}{align}{width - 2*(1 + len(chars))}}{chars[::-1]}{char0}"
|
|
73
|
+
|
|
74
|
+
################################### FORMAT WIDTH ###################################
|
|
75
|
+
|
|
76
|
+
def get_width(width: str, box: str, style: str, char_len: int, fmt_header: str) -> int:
|
|
77
|
+
"""Determine the width of the header based on input parameters."""
|
|
78
|
+
|
|
79
|
+
default: int = 84
|
|
80
|
+
header_width: int = len(fmt_header) + 2 * char_len
|
|
81
|
+
|
|
82
|
+
is_auto_width: list[bool] = [
|
|
83
|
+
width.lower() == "auto",
|
|
84
|
+
width.lower() == "default" and style.lower() == "boxed",
|
|
85
|
+
width.lower() == "default" and box.lower() != "none"
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
if width.lower() == 'default' and box.lower() == 'none':
|
|
89
|
+
return default
|
|
90
|
+
if any(is_auto_width):
|
|
91
|
+
return header_width
|
|
92
|
+
try:
|
|
93
|
+
_width = int(width)
|
|
94
|
+
if _width <= 0:
|
|
95
|
+
warnings.warn(f"Invalid option {width}, using default (84).")
|
|
96
|
+
return default
|
|
97
|
+
return max(_width, header_width)
|
|
98
|
+
except ValueError:
|
|
99
|
+
warnings.warn(f"Invalid option {width}, using default (84).")
|
|
100
|
+
return default
|
|
101
|
+
|
|
102
|
+
################################# FORMAT ALIGNMENT #################################
|
|
103
|
+
|
|
104
|
+
def get_align(align: str, box: str, style: str) -> str:
|
|
105
|
+
"""Determine the alignment of the header based on input parameters."""
|
|
106
|
+
|
|
107
|
+
is_default_center: list[bool] = [
|
|
108
|
+
align.lower() == "default" and box.lower() != "none",
|
|
109
|
+
style.lower() == "single",
|
|
110
|
+
style.lower() == "boxed"
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
if align.lower() == "left":
|
|
114
|
+
return "<"
|
|
115
|
+
if align.lower() == "right":
|
|
116
|
+
return ">"
|
|
117
|
+
if align.lower() == "center":
|
|
118
|
+
return "^"
|
|
119
|
+
if any(is_default_center):
|
|
120
|
+
return "^"
|
|
121
|
+
if align.lower() == "default" and style.lower() == "multi":
|
|
122
|
+
return "<"
|
|
123
|
+
warnings.warn(f"Invalid option {align}. Using default (center).")
|
|
124
|
+
return "^"
|
|
125
|
+
|
|
126
|
+
################################ BOX HEADER FORMAT #################################
|
|
127
|
+
|
|
128
|
+
def draw_boxed(head, box: str, width: int, align: str) -> str:
|
|
129
|
+
"""Draw a box around the header text based on the specified box style."""
|
|
130
|
+
|
|
131
|
+
if box == 'thick': # style 3
|
|
132
|
+
v = "┃" # vertical
|
|
133
|
+
h = "━" # horizontal
|
|
134
|
+
ul = "┏" # upper left
|
|
135
|
+
ur = "┓" # upper right
|
|
136
|
+
bl = "┗" # bottom left
|
|
137
|
+
br = "┛" # bottom right
|
|
138
|
+
elif box == 'round': # style 4
|
|
139
|
+
v = "│" # vertical
|
|
140
|
+
h = "─" # horizontal
|
|
141
|
+
ul = "╭" # upper left
|
|
142
|
+
ur = "╮" # upper right
|
|
143
|
+
bl = "╰" # bottom left
|
|
144
|
+
br = "╯" # bottom right
|
|
145
|
+
elif box == 'double': # style 1
|
|
146
|
+
v = "║" # vertical
|
|
147
|
+
h = "═" # horizontal
|
|
148
|
+
ul = "╔" # upper left
|
|
149
|
+
ur = "╗" # upper right
|
|
150
|
+
bl = "╚" # bottom left
|
|
151
|
+
br = "╝" # bottom right
|
|
152
|
+
else:
|
|
153
|
+
# Default
|
|
154
|
+
v = "│" # vertical
|
|
155
|
+
h = "─" # horizontal
|
|
156
|
+
ul = "┌" # upper left
|
|
157
|
+
ur = "┐" # upper right
|
|
158
|
+
bl = "└" # bottom left
|
|
159
|
+
br = "┘" # bottom right
|
|
160
|
+
|
|
161
|
+
top = ul + h * (width - 2) + ur
|
|
162
|
+
bottom = bl + h * (width - 2) + br
|
|
163
|
+
|
|
164
|
+
return f"{top}\n{v}{head:{align}{width - 2}}{v}\n{bottom}"
|
|
165
|
+
|
|
166
|
+
####################################################################################
|
|
167
|
+
# - MAIN -
|
|
168
|
+
####################################################################################
|
|
169
|
+
|
|
170
|
+
def main():
|
|
171
|
+
""" Main function to parse arguments and generate the header. """
|
|
172
|
+
|
|
173
|
+
############################### - PARSER SETUP - ###############################
|
|
174
|
+
|
|
175
|
+
parser = argparse.ArgumentParser(
|
|
176
|
+
description="Format a title with a border.",
|
|
177
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
####################### - VALUE OPTIONS CONFIGURATION - ########################
|
|
181
|
+
|
|
182
|
+
parser.add_argument("head", nargs="?", help="The header text")
|
|
183
|
+
|
|
184
|
+
parser.add_argument(
|
|
185
|
+
"-H", "--head", dest="header",
|
|
186
|
+
help="The header text (alternative flag form)."
|
|
187
|
+
)
|
|
188
|
+
parser.add_argument(
|
|
189
|
+
"-s", "--style", choices=["single", "multi", "boxed"],
|
|
190
|
+
default="single", help="Border style."
|
|
191
|
+
)
|
|
192
|
+
parser.add_argument(
|
|
193
|
+
"-c", "--char", default="#",
|
|
194
|
+
help="Character to use for the border."
|
|
195
|
+
)
|
|
196
|
+
parser.add_argument(
|
|
197
|
+
"-w", "--width", default='default',
|
|
198
|
+
help="Width of the rows.", type=str
|
|
199
|
+
)
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
"-b", "--box", choices=["thin", "thick", "round", "double"],
|
|
202
|
+
default='none', help="Used do display boxed text.", type=str
|
|
203
|
+
)
|
|
204
|
+
parser.add_argument(
|
|
205
|
+
"-a", "--align", choices=['left', 'right', 'center'],
|
|
206
|
+
default='default', help="Used do display boxed text.", type=str
|
|
207
|
+
)
|
|
208
|
+
parser.add_argument(
|
|
209
|
+
"--border-only", action="store_true",
|
|
210
|
+
help="Display only the border without the header text."
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
####################### - BOOLEAN FLAGS CONFIGURATION - ########################
|
|
214
|
+
|
|
215
|
+
case_group = parser.add_mutually_exclusive_group()
|
|
216
|
+
case_group.add_argument(
|
|
217
|
+
"-U", "--upper", action="store_true",
|
|
218
|
+
help="Converts header to UPPERCASE."
|
|
219
|
+
)
|
|
220
|
+
case_group.add_argument(
|
|
221
|
+
"-L" ,"--lower", action="store_true",
|
|
222
|
+
help="Converts header to lowercase."
|
|
223
|
+
)
|
|
224
|
+
case_group.add_argument(
|
|
225
|
+
"-T", "--title", action="store_true",
|
|
226
|
+
help="Converts header to Title_Case."
|
|
227
|
+
)
|
|
228
|
+
case_group.add_argument(
|
|
229
|
+
"-S", "--swapcase", action="store_true",
|
|
230
|
+
help="Converts header to sWAPcASE."
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
############################# - ARGUMENT PARSING - #############################
|
|
234
|
+
|
|
235
|
+
args = parser.parse_args()
|
|
236
|
+
|
|
237
|
+
############################ - HEADER FORMATTING - #############################
|
|
238
|
+
|
|
239
|
+
# Prefer --head flag over positional head
|
|
240
|
+
head = args.header or args.head
|
|
241
|
+
|
|
242
|
+
if not head:
|
|
243
|
+
# If neither positional nor flag provided, read from stdin (pipe)
|
|
244
|
+
if not sys.stdin.isatty():
|
|
245
|
+
head = sys.stdin.read().strip()
|
|
246
|
+
else:
|
|
247
|
+
|
|
248
|
+
if not args.border_only:
|
|
249
|
+
parser.error(
|
|
250
|
+
"No header text provided. Use positional argument,"
|
|
251
|
+
"-H/--head flag, or pipe input."
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
head = ""
|
|
255
|
+
|
|
256
|
+
if args.upper:
|
|
257
|
+
head = head.upper()
|
|
258
|
+
elif args.lower:
|
|
259
|
+
head = head.lower()
|
|
260
|
+
elif args.title:
|
|
261
|
+
head = head.title()
|
|
262
|
+
elif args.swapcase:
|
|
263
|
+
head = head.swapcase()
|
|
264
|
+
|
|
265
|
+
############################## - FUNCTION CALL - ###############################
|
|
266
|
+
|
|
267
|
+
print(hfmt(head, args))
|
|
268
|
+
|
|
269
|
+
####################################################################################
|
|
270
|
+
# - EXEC -
|
|
271
|
+
####################################################################################
|
|
272
|
+
|
|
273
|
+
if __name__ == "__main__":
|
|
274
|
+
main()
|
|
275
|
+
|
|
276
|
+
####################################################################################
|
|
277
|
+
# - END -
|
|
278
|
+
####################################################################################
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hfmt-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple CLI utility for generating formatted text headers with borders and boxes.
|
|
5
|
+
Author: Bogdan Pricope
|
|
6
|
+
License: BSD 3-Clause License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025, Bogdan Pricope
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions are met:
|
|
12
|
+
|
|
13
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
14
|
+
list of conditions and the following disclaimer.
|
|
15
|
+
|
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
|
18
|
+
and/or other materials provided with the distribution.
|
|
19
|
+
|
|
20
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
21
|
+
contributors may be used to endorse or promote products derived from
|
|
22
|
+
this software without specific prior written permission.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
25
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
26
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
32
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
+
|
|
35
|
+
Keywords: cli,formatting,headers,borders,boxes,ascii,unicode
|
|
36
|
+
Requires-Python: >=3.9
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# hfmt-cli
|
|
42
|
+
|
|
43
|
+
<p align="left">
|
|
44
|
+
<img src="https://badges.fw-web.space/github/license/BogdanPri/header-cli?style=flat-square">
|
|
45
|
+
<img src="https://badges.fw-web.space/github/languages/code-size/BogdanPri/header-cli?style=flat-square">
|
|
46
|
+
<img alt="GitHub top language" src="https://badges.fw-web.space/github/languages/top/BogdanPri/header-cli?style=flat-square">
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
A simple CLI utility for generating formatted text headers with borders and boxes.
|
|
50
|
+
|
|
51
|
+
## 📦 Requirements
|
|
52
|
+
|
|
53
|
+
* Python >= 3.9
|
|
54
|
+
|
|
55
|
+
## 🛠 Usage
|
|
56
|
+
|
|
57
|
+
Run with a positional argument:
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
$ hfmt "project title"
|
|
61
|
+
################################## project title ###################################
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Run with flags:
|
|
66
|
+
```console
|
|
67
|
+
$ hfmt --head "build complete" --style multi --char "=" --width 60 --upper --align left
|
|
68
|
+
============================================================
|
|
69
|
+
= BUILD COMPLETE
|
|
70
|
+
============================================================
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```console
|
|
74
|
+
$ hfmt --border-only --width 50
|
|
75
|
+
##################################################
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Run with box mode:
|
|
79
|
+
```console
|
|
80
|
+
$ hfmt --title --width auto --box double "welcome back"
|
|
81
|
+
╔══════════════╗
|
|
82
|
+
║ Welcome Back ║
|
|
83
|
+
╚══════════════╝
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### ⚙️ Options
|
|
87
|
+
|
|
88
|
+
`hfmt-cli` supports the following value flags:
|
|
89
|
+
|
|
90
|
+
| Flag | Description | Default |
|
|
91
|
+
|------|-------------|---------|
|
|
92
|
+
| `head` (positional) | Header text | — |
|
|
93
|
+
| `-H, --head` | Header text (alternative flag form) | — |
|
|
94
|
+
| `-s, --style` | Border style (`single`, `multi`) | `single` |
|
|
95
|
+
| `-c, --char` | Character to use for the border | `#` |
|
|
96
|
+
| `-w, --width` | Width of the rows | `84` or `auto` |
|
|
97
|
+
| `-a, --align` | Header justification | `center` or `left` |
|
|
98
|
+
| `-b, --box` | Surround header by a box (overrides other flags) | `none` |
|
|
99
|
+
|
|
100
|
+
`hfmt-cli` supports the following value toggles:
|
|
101
|
+
|
|
102
|
+
| Toggle | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `-U, --upper` | Converts header to "UPPER_CASE" |
|
|
105
|
+
| `-L, --lower` | Converts header to "lower_case" |
|
|
106
|
+
| `-T, --title` | Converts header to "Title_Case" |
|
|
107
|
+
| `-S, --swapcase` | Converts header to "sWAP_cASE" |
|
|
108
|
+
| `--border-only` | Returns only a border of characters with no header |
|
|
109
|
+
|
|
110
|
+
## 🚀 Installation
|
|
111
|
+
|
|
112
|
+
Clone the git repo:
|
|
113
|
+
```console
|
|
114
|
+
git clone https://www.github.com/BogdanPri/hfmt-cli.git
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Install via `pip`:
|
|
118
|
+
```console
|
|
119
|
+
cd hfmt-cli
|
|
120
|
+
pip install -e .
|
|
121
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/hfmt/__init__.py
|
|
5
|
+
src/hfmt/cli.py
|
|
6
|
+
src/hfmt_cli.egg-info/PKG-INFO
|
|
7
|
+
src/hfmt_cli.egg-info/SOURCES.txt
|
|
8
|
+
src/hfmt_cli.egg-info/dependency_links.txt
|
|
9
|
+
src/hfmt_cli.egg-info/entry_points.txt
|
|
10
|
+
src/hfmt_cli.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hfmt
|