Skip to content

Commit 225c9c7

Browse files
committed
update dotfiles cli
1 parent 6dc40bb commit 225c9c7

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

src/dotware/dotfiles/cli.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from inspect import isfunction
2121
from typing_extensions import Annotated
2222

23+
from dotware import config
2324
from dotware.config import *
2425
from dotware import __pkg_name__, __version__
2526
from dotware.registry import *
@@ -78,10 +79,16 @@ def showComponents(type: Annotated[str, typer.Argument(help="Component Type")]):
7879
compdir = COMPLETIONS
7980
case 'functions':
8081
compdir = FUNCTIONS
82+
case 'packages':
83+
compdir = PACKAGES
8184
case 'plugins':
8285
compdir = PLUGINS
86+
case 'scripts':
87+
compdir = SCRIPTS
88+
case 'stacks':
89+
compdir = STACKS
8390
case _:
84-
logger.error(f"Unknown component type '{type}'. Valid types are: {', '.join(SELECTABLE_TYPES)}")
91+
logger.error(f"Unknown component type '{type}'. Valid types are: {', '.join([t[0] for t in COMPONENT_TYPES])}")
8592
raise typer.Exit(code=1)
8693

8794
if not compdir.exists():
@@ -92,7 +99,26 @@ def showComponents(type: Annotated[str, typer.Argument(help="Component Type")]):
9299
i = 1
93100
files = [f.name for f in compdir.iterdir() if f.is_file()]
94101
for file in files:
95-
pass
102+
try:
103+
compfile = compdir / file
104+
if not compfile.exists():
105+
logger.error(f"Component file '{compfile}' does not exist.")
106+
continue
107+
if type in SELECTABLE_TYPES:
108+
status = Registry._status(compfile)
109+
if status == 0:
110+
status_symbol = SYMBOL_SUCCESS
111+
elif status == 1:
112+
status_symbol = " "
113+
else:
114+
status_symbol = SYMBOL_ERROR
115+
else:
116+
status_symbol = " "
117+
logger.info(f"{i}. {status_symbol} {file}")
118+
i += 1
119+
except Exception as e:
120+
logger.error(f"Error processing file '{file}': {e}")
121+
raise
96122

97123
except Exception as e:
98124
logger.error(f"Failed to show components of type '{type}': {e}")
@@ -131,6 +157,7 @@ def installPackage(name: Annotated[str, typer.Argument(help="Package Name")]):
131157
preinstall = f"{name}::pre_install"
132158
installfnc = f"{name}::install"
133159
postinstall = f"{name}::post_install"
160+
configfnc = f"{name}::config"
134161
if not pkgfile.exists():
135162
logger.error(f"Package directory '{pkgfile}' does not exist.")
136163
raise typer.Exit(code=1)
@@ -166,6 +193,9 @@ def installPackage(name: Annotated[str, typer.Argument(help="Package Name")]):
166193
else:
167194
logger.info(f"Post-installation hook executed successfully for package '{name}'.")
168195

196+
if grepFile(pkgfile, configfnc):
197+
logger.info(typer.style(f"Package also includes configuration hook", fg=config.COLOR_WARNING, bold=True))
198+
169199
except Exception as e:
170200
logger.error(f"Failed to install package '{name}': {e}")
171201
raise

src/dotware/meta.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Component:
2626
desc: str
2727
tags: list[str]
2828

29-
_filepath: Path
30-
_status: int = 1
29+
filepath: Path
30+
status: int = 1
3131

3232

3333

@@ -77,9 +77,9 @@ def searchPath(self, path: Path, clear: bool = False, recursive: bool = True):
7777
desc = line.split(':', 1)[1].strip()
7878
elif line.startswith('# Tags:'):
7979
tags = [tag.strip() for tag in line.split(':', 1)[1].split(',')]
80-
elif line.startswith('# FUNCTIONS'):
80+
elif line.startswith('###########'):
8181
break
82-
component = Component(name=name, desc=desc, tags=tags, _filepath=file, _status=Registry._status(file))
82+
component = Component(name=name, desc=desc, tags=tags, filepath=file, status=Registry._status(file))
8383
self._components.append(component)
8484
if found:
8585
break

src/dotware/registry.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ def _checkFile(file: Path):
7676
def _status(id: Path | str) -> int:
7777
""" Check the status of a component """
7878

79-
if isinstance(id, Path):
80-
if not id.is_file():
81-
logger.error(f"Path '{id}' is not a file.")
82-
return 20
83-
if Registry._checkFile(id) != 0:
84-
logger.error(f"File '{id}' is not a valid component file.")
85-
return 20
86-
name = id.name
87-
elif isinstance(id, str):
88-
name = id
89-
else:
90-
logger.error(f"Invalid component ID type: {type(id)}. Must be a Path or str.")
91-
return 10
79+
if isinstance(id, str):
80+
id = Path(id)
81+
82+
if not id.is_file():
83+
logger.error(f"Path '{id}' is not a file.")
84+
return 3
85+
if Registry._checkFile(id) != 0:
86+
logger.error(f"File '{id}' is not a valid component file.")
87+
return 2
88+
name = id.name
9289

9390
parts = name.split('.')
9491
regfile = REGISTRY / f"{parts[1]}.enabled"

sys/lib/aliases/general.aliases.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424

2525
# Add an "alert" alias for long running commands. Use like so:
2626
# sleep 10; alert
27-
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
27+
# alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
2828

2929
# maintain scrollback on clear
3030
alias clear='clear -x'

sys/lib/pkgs/asdf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ asdf::install()
2828

2929
sudo ex asdf-*.tar.gz -C /usr/local/bin
3030

31-
if [ ! -f "$CUSTOM/99-custom.bash" ]; then
32-
echo "source <(asdf completion bash)" > "$CUSTOM/99-custom.bash"
33-
ln -s "$CUSTOM/99-custom.bash" "$BASHRCD/99-custom.bash"
31+
if [ ! -f "$CUSTOM/dots/.bashrc.d/99-custom.bash" ]; then
32+
echo "source <(asdf completion bash)" > "$CUSTOM/dots/.bashrc.d/99-custom.bash"
33+
ln -s "$CUSTOM/dots/.bashrc.d/99-custom.bash" "$BASHRCD/99-custom.bash"
3434
else
35-
echo "source <(asdf completion bash)" >> "$CUSTOM/99-custom.bash"
35+
echo "source <(asdf completion bash)" >> "$CUSTOM/dots/.bashrc.d/99-custom.bash"
3636
fi
3737
}
3838
#-------------------------------------------------------------------

0 commit comments

Comments
 (0)