Skip to content

Conversation

@faretek1
Copy link
Collaborator

@faretek1 faretek1 commented Oct 4, 2025

Solves issue #478

Changes

This PR adds a CLI via the __main__.py file and the cli submodule. It adds a console script scratch when installed with pip. If you want to develop it, you will need to reinstall scratchattach (pip install -e .).

It is based on the specification here, which will later be made into a tutorial.

Each command will be split into a separate file within cli/cmd, and be imported via cli/cmd/__init__.py.

Note

I have not added the CLI to scratchattach/__init__.py. I do not see a reason to. Any future features like pretty printing of e.g. Activity will be implemented directly into scratchattach through some method. I will probably call it something like .rich_format()

The CLI uses sqlite3 (this is in the python standard library) to store session ids with usernames. It (will) use rich for colored and formatted output.
image

Tests

It is a good question to consider how the CLI could be tested. I am not sure what the best means is.

TODO

  • Delete group
  • Copy group
  • rename group
  • list sessions
  • save passwords (to circumvent sessid expiry)

@faretek1 faretek1 added enhancement New feature or request help wanted Extra attention is needed question Further information is requested labels Oct 4, 2025
@TimMcCool
Copy link
Owner

This looks really cool and useful!

It doesn't seem to cause any issues, although there is no reason to import it
@faretek1

This comment was marked as resolved.

@faretek1
Copy link
Collaborator Author

faretek1 commented Oct 5, 2025

ideally, all sql commands should be moved to ctx.py or db.py

@faretek1
Copy link
Collaborator Author

faretek1 commented Oct 5, 2025

you can try commands like scratch -U timmccool

once the groups system is finished, i intend on merging this. Then, more features, e.g. commenting etc, can be added later.
I added a version number in sa/cli/about but im not sure if this is worth updating

I also added an optional dependency rich-pixels for rendering thumbnails within the terminal. If an import error occurs, the image rendering will be skipped.

@faretek1 faretek1 removed the help wanted Extra attention is needed label Oct 6, 2025
@faretek1
Copy link
Collaborator Author

faretek1 commented Oct 9, 2025

It may be a good idea to try and steer away from this 'fake TUI'-like output. Maybe I will try to make it more like github's CLI

@TheCommCraft
Copy link
Collaborator

how is it fake tui

@faretek1
Copy link
Collaborator Author

it uses panels and layouts which is like a tui, but it still uses commands. using panels takes a lot of space

@faretek1
Copy link
Collaborator Author

possibly, a tui could be developed separately, e.g. using textualise

@faretek1
Copy link
Collaborator Author

for now, i will leave the user/project.__rich__ methods as is. I will instead finish up the group system, move the sql to one file, then merge

@faretek1
Copy link
Collaborator Author

faretek1 commented Oct 11, 2025

how should sessions be represented? -L for login? or --session (-S is for studio)

Also changed __str__ representation. This should be implemented into CLI before publish
@faretek1
Copy link
Collaborator Author

faretek1 commented Oct 11, 2025

possibly we could use verbose parameter names for the string reprs, idk

e.g. a timmccool user.User object -> --username TimMcCool instead of -U TimMcCool

@faretek1 faretek1 marked this pull request as ready for review October 11, 2025 18:15
@faretek1
Copy link
Collaborator Author

I will add some more to-dos as issues but i want to merge this so that i don't need to sync it all the time

@faretek1 faretek1 merged commit e09d727 into main Oct 11, 2025
1 check passed
@faretek1 faretek1 deleted the cli branch October 11, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants