Fixed project versioning. Added some initial argument parsing.

This commit is contained in:
Gnarwhal 2024-07-31 22:08:18 +00:00
parent a310c28a52
commit cde4bffb0d
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
6 changed files with 79 additions and 2 deletions

2
.gitignore vendored
View file

@ -160,3 +160,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Version file
_version.py

View file

@ -1,6 +1,6 @@
# SSHare
Convenience script for uploading files to a server via ssh
Upload files to a server via ssh
### Hmmm

View file

@ -28,3 +28,5 @@ Issues = "https://forge.monodon.me/Gnarwhal/sshare/issues"
[project.scripts]
sshare = "sshare.cli:main"
[tool.setuptools_scm]
version_file = "src/sshare/_version.py"

0
src/sshare/__init__.py Normal file
View file

View file

@ -1,3 +1,17 @@
# This file is part of SSHare.
#
# SSHare is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# SSHare is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
from cli import main
main()

View file

@ -10,18 +10,23 @@
# more details.
#
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
# SSHare. If not, see <https://www.gnu.org/licenses/>.
import argparse
import getpass
import importlib.util
import os
import os.path
import pkg_resources
import pyclip
import time
import subprocess
import sys
import _version
def main():
arguments = parse_arguments()
config = Config()
file = _latest("/home/gnarwhal/Pictures/Screenshots")
@ -49,6 +54,60 @@ def main():
sys.exit(0)
def parse_arguments():
parser = argparse.ArgumentParser(
prog = "SSHare",
description = "Upload files to a server via ssh",
formatter_class = argparse.RawDescriptionHelpFormatter,
epilog =
"""
Configuration Files:
Configuration files will be looked for in
'$XDG_CONFIG_DIR/sshare/'. If XDG_DATA_DIR is not set,
SSHare will fallback to '$HOME/.config/sshare/'.
If it exists, `default.py' will be considered as config[0].
Otherwise, all other configuration files will be ordered
alphabetically.
"""
)
parser.add_argument(
"-v",
"--version",
action="version",
version=f"%(prog)s version {_version.version}",
)
parser.add_argument(
"-l",
"--list",
action="store_const",
help="List available configuration files",
)
parser.add_argument(
"-c",
"--config",
help="Use the config at location CONFIG",
)
parser.add_argument(
"-n",
"--number",
type=int,
default=0,
help="Use config number n (Default: 0)",
)
parser.add_argument(
"-i",
"--interactive",
action="store_const",
help="Run interactively",
)
arguments = parser.parse_args()
return arguments
def _latest(directory, key=os.path.getmtime):
files = map(lambda file: f"{directory}/{file}", os.listdir(directory))
selection = next(files)