Skip to content

Commit 997e1f4

Browse files
Add CLI tool for user signup with API integration
1 parent 2603d7f commit 997e1f4

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

.github/workflows/api-docker-image.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Image CI
1+
name: API Docker Image
22

33
on:
44
push:
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CLI Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
jobs:
12+
publish:
13+
name: Publish to PyPI
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: "3.9"
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install build
29+
30+
- name: Build the package
31+
run: python -m build CLI
32+
33+
- name: Publish to PyPI
34+
uses: pypa/gh-action-pypi-publish@release/v1
35+
with:
36+
password: ${{ secrets.PYPI_API_TOKEN }}

CLI/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Upayan Mazumder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

CLI/cas/cli.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import argparse
2+
import requests
3+
import sys
4+
5+
API_BASE_URL = "https://api.cas.upayan.dev"
6+
SIGNUP_ENDPOINT = f"{API_BASE_URL}/auth/signup"
7+
8+
def signup_user(email, password):
9+
"""
10+
Sends a signup request to the API.
11+
"""
12+
try:
13+
response = requests.post(
14+
SIGNUP_ENDPOINT,
15+
json={"email": email, "password": password},
16+
)
17+
if response.status_code == 201:
18+
print(f"User signed up successfully!\n{response.json()}")
19+
else:
20+
print(f"Failed to sign up user.\nError: {response.json().get('error', 'Unknown error')}")
21+
except requests.exceptions.RequestException as e:
22+
print(f"Error connecting to the API: {e}")
23+
sys.exit(1)
24+
25+
def main():
26+
parser = argparse.ArgumentParser(description="CLI tool for signing up users.")
27+
parser.add_argument(
28+
"action",
29+
choices=["signup"],
30+
help="Action to perform. Currently supports only 'signup'."
31+
)
32+
parser.add_argument("-e", "--email", required=True, help="Email address of the user.")
33+
parser.add_argument("-p", "--password", required=True, help="Password for the user.")
34+
args = parser.parse_args()
35+
36+
if args.action == "signup":
37+
signup_user(args.email, args.password)

CLI/cas/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
argparse
2+
requests
3+
sys

CLI/pyproject.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "cas"
7+
version = "0.1.0"
8+
description = "Command-line interface for interacting with the CAS API"
9+
authors = [
10+
{ name = "upayan", email = "[email protected]" }
11+
]
12+
license = { text = "MIT" }
13+
readme = "README.md"
14+
requires-python = ">=3.7"
15+
dependencies = ["requests","sys","argparse"]
16+
17+
[project.scripts]
18+
cas = "cas.cli:main"

0 commit comments

Comments
 (0)