karlot / sshclick

SSH Config terminal manager based on Python and Click framework with Rich and Textual UI
MIT License
51 stars 1 forks source link

If there is no .ssh/config file, the app crashes #3

Closed vincecima closed 5 days ago

vincecima commented 6 days ago

I tried running the app (via uv and uvx) and it crashed because I don't have a .ssh/config currently.

❯ uvx --from sshclick sshc hosts
Traceback (most recent call last):
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/bin/sshc", line 10, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
    ~~~~~~~~~~~~~~^^^^^
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/sshclick/main.py", line 33, in cli
    ctx.obj = SSH_Config(file=os.path.expanduser(sshconfig), stdout=stdout).read().parse()
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/vincecima/.cache/uv/archive-v0/2RzSQ8LcQbX_wzBGQA8Jj/lib/python3.13/site-packages/sshclick/sshc/ssh_config.py", line 43, in read
    with open(self.ssh_config_file, "r") as fh:
         ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/vincecima/.ssh/config'

The same error happens for many of the commands.

Just to confirm I have no file there:

❯ ls ~/.ssh/config
"/Users/vincecima/.ssh/config": No such file or directory (os error 2)
karlot commented 5 days ago

Thanks for opening the issue, to be honest, I really never had tested it without the config file. :/ Since I haven't update the project in a while, I have some pending changes to merge, and will include fix for this as well in next days probably. I assume if SSH config file is not present, prompt will be asked if it should be created automatically for the user. If that's declined, well... I guess CLI should just abort as there is no data to work with.