Skip to content

Commit 4e93af8

Browse files
authored
Merge pull request #13 from simplyblock-io/sbcli-subrepository
Implemented sbcli repository access to get the latest cli-reference.yaml file
2 parents 55fc6bf + d2ba4d8 commit 4e93af8

File tree

6 files changed

+61
-2385
lines changed

6 files changed

+61
-2385
lines changed

.github/workflows/mkdocs.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
./doc-builder build-image
4141
- name: "Build Documentation Test"
4242
run: |
43+
./doc-builder update-repositories
4344
./doc-builder build
4445
dev-deployment:
4546
if: ${{ github.ref == 'refs/heads/main' }}
@@ -57,6 +58,7 @@ jobs:
5758
run: |
5859
sed -i -r "s|(site_url: .*)|\1dev/|g" ./mkdocs.yml
5960
cat ./mkdocs.yml
61+
./doc-builder update-repositories
6062
./doc-builder build
6163
- name: "Upload Documentation"
6264
uses: SamKirkland/[email protected]
@@ -84,6 +86,7 @@ jobs:
8486
echo "RELEASE_NAME=$(echo ${name} | sed -e 's/.*\///g')" >> $GITHUB_ENV
8587
- name: "Prepare Documentation Deployment: ${{ env.RELEASE_NAME }}"
8688
run: |
89+
./doc-builder update-repositories
8790
./doc-builder deploy ${{ env.RELEASE_NAME }}
8891
- name: "Create Version Tag: ${{ env.RELEASE_NAME }}"
8992
run: |

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
site
44
venv
55
.idea
6-
docs/reference/cli
6+
docs/reference/cli
7+
scripts/sbcli-repo

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ needs to be built using:
4040
./doc-builder build-image
4141
```
4242

43+
In addition, external repositories have to be checked out, to generate the necessary documentation pages. The
44+
`doc-builder` simplifies this process with a specific command which either creates an initial checkout or updates the
45+
repositories to the latest commit.
46+
47+
```bash
48+
./doc-builder update-repositories
49+
```
50+
51+
The command can be run at any time to update the external repositories to the latest commit.
52+
4353
### Serving Content Locally
4454

4555
When building or updating the documentation, it is useful to have a local builder with live updating. Mkdocs supports

doc-builder

+45-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ if ! [[ "${JQ}" ]]; then
2323
exit 1
2424
fi
2525

26+
GIT=$(command -v git)
27+
if ! [[ "${GIT}" ]]; then
28+
echo "Command git not found. Please install git."
29+
exit 1
30+
fi
31+
2632
function ensure_docker_image() {
2733
echo -n "Checking docker build image... "
2834
local image=$(${DOCKER} image ls | ${GREP} ${IMAGE_NAME})
@@ -34,6 +40,21 @@ function ensure_docker_image() {
3440
exit 1
3541
}
3642

43+
function update_repositories() {
44+
if [ ! -d ./scripts/sbcli-repo ]; then
45+
echo "Cloning sbcli repository..."
46+
git clone https://github.com/simplyblock-io/sbcli.git ./scripts/sbcli-repo
47+
else
48+
echo "Updating sbcli repository..."
49+
pushd ./scripts/sbcli-repo
50+
git reset --hard
51+
git pull -f
52+
local ret=$?
53+
popd
54+
exit ${ret}
55+
fi
56+
}
57+
3758
function build_image() {
3859
docker build -t ${IMAGE_NAME} .
3960
exit $?
@@ -45,6 +66,16 @@ function serve() {
4566
exit $?
4667
}
4768

69+
function gen_sbcli_ref() {
70+
if [ ! -d ./scripts/sbcli-repo ]; then
71+
echo "The sbcli repository not yet available. Please run ./doc-builder update-sbcli and try again."
72+
exit 1
73+
fi
74+
75+
echo "Generating sbcli reference pages..."
76+
${DOCKER} run --rm ${terminal} -v "${PWD}":/docs --entrypoint="/usr/local/bin/python" ${IMAGE_NAME} /docs/scripts/cli-reference-gen.py /docs
77+
}
78+
4879
function build() {
4980
ensure_docker_image
5081
echo -n "Cleaning site directory... "
@@ -57,8 +88,10 @@ function build() {
5788
terminal="-t"
5889
fi
5990

60-
echo "Generating CLI reference pages..."
61-
${DOCKER} run --rm ${terminal} -v "${PWD}":/docs --entrypoint="/usr/local/bin/python" ${IMAGE_NAME} /docs/scripts/cli-reference-gen.py /docs
91+
# Generates the markdown files for the sbcli reference pages
92+
if ! gen_sbcli_ref; then
93+
exit 1
94+
fi
6295

6396
echo "Building documentation... "
6497
if ! ${DOCKER} run --rm ${terminal} -v "${PWD}:/docs" ${IMAGE_NAME} build --strict "$@"; then
@@ -135,10 +168,20 @@ case "$1" in
135168
deploy "${@:2}"
136169
;;
137170

171+
"update-repositories")
172+
update_repositories
173+
;;
174+
175+
"gen-sbcli-ref")
176+
gen_sbcli_ref
177+
;;
178+
138179
*)
139180
echo "Simplyblock Documentation Builder"
140181
echo "Available commands:"
141182
echo " ./doc-builder build-image Building required docker image"
183+
echo " ./doc-builder update-repositories Initialized or updated external repository"
184+
echo " ./doc-builder gen-sbcli-ref Generates the sbcli reference pages"
142185
echo " ./doc-builder serve Live serving content changes"
143186
echo " ./doc-builder build Building static documentation"
144187
echo " ./doc-builder deploy {version-name} Preparing new version deployment "

scripts/cli-reference-gen.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ def get_description(item):
6969

7070

7171
base_path = sys.argv[1]
72-
with open("%s/scripts/cli-reference.yaml" % base_path) as stream:
72+
with open("%s/scripts/sbcli-repo/cli-reference.yaml" % base_path) as stream:
7373
try:
7474
reference = yaml.safe_load(stream)
7575

7676
for command in reference["commands"]:
7777
for subcommand in command["subcommands"]:
7878
if "arguments" in subcommand:
79-
for argument in subcommand["arguments"]:
80-
argument["required"] = False if "default" not in argument else True
8179
arguments = select_arguments(subcommand["arguments"])
8280
parameters = select_parameters(subcommand["arguments"])
8381
subcommand["arguments"] = arguments

0 commit comments

Comments
 (0)