cfengine 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {cfengine-0.3.0 → cfengine-0.4.0}/.github/dependabot.yml +8 -0
  2. {cfengine-0.3.0 → cfengine-0.4.0}/.github/workflows/black-check.yml +3 -0
  3. {cfengine-0.3.0 → cfengine-0.4.0}/.github/workflows/black-format.yml +4 -0
  4. cfengine-0.4.0/.github/workflows/pypi-publish.yml +60 -0
  5. cfengine-0.4.0/.github/workflows/tests.yml +31 -0
  6. {cfengine-0.3.0 → cfengine-0.4.0}/.gitignore +2 -1
  7. {cfengine-0.3.0 → cfengine-0.4.0}/HACKING.md +58 -3
  8. {cfengine-0.3.0 → cfengine-0.4.0}/PKG-INFO +42 -9
  9. {cfengine-0.3.0 → cfengine-0.4.0}/README.md +36 -5
  10. cfengine-0.4.0/ci/01-install.sh +6 -0
  11. cfengine-0.4.0/ci/02-safe-tests.sh +9 -0
  12. cfengine-0.4.0/ci/03-unsafe-tests.sh +11 -0
  13. {cfengine-0.3.0 → cfengine-0.4.0}/pyproject.toml +4 -2
  14. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine.egg-info/PKG-INFO +42 -9
  15. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine.egg-info/SOURCES.txt +13 -4
  16. cfengine-0.4.0/src/cfengine.egg-info/requires.txt +5 -0
  17. cfengine-0.4.0/src/cfengine_cli/commands.py +96 -0
  18. cfengine-0.4.0/src/cfengine_cli/dependency_tables.py +2 -0
  19. cfengine-0.4.0/src/cfengine_cli/dev.py +52 -0
  20. cfengine-0.4.0/src/cfengine_cli/docs_formatting.py +264 -0
  21. cfengine-0.4.0/src/cfengine_cli/format.py +227 -0
  22. cfengine-0.4.0/src/cfengine_cli/lint.py +123 -0
  23. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/main.py +43 -19
  24. cfengine-0.4.0/tests/shell/001-help.sh +7 -0
  25. cfengine-0.4.0/tests/shell/002-version.sh +8 -0
  26. cfengine-0.4.0/tests/test_paths.py +19 -0
  27. cfengine-0.4.0/tests/test_utils.py +8 -0
  28. cfengine-0.4.0/tests/test_version.py +6 -0
  29. {cfengine-0.3.0 → cfengine-0.4.0}/uv.lock +141 -4
  30. cfengine-0.3.0/.github/workflows/pypi-publish.yml +0 -34
  31. cfengine-0.3.0/.github/workflows/tests.yml +0 -56
  32. cfengine-0.3.0/main.py +0 -6
  33. cfengine-0.3.0/src/cfengine.egg-info/requires.txt +0 -2
  34. cfengine-0.3.0/src/cfengine_cli/commands.py +0 -26
  35. cfengine-0.3.0/tests/docker/001-docker-install-test.sh +0 -36
  36. cfengine-0.3.0/tests/docker/Dockerfile +0 -10
  37. cfengine-0.3.0/tests/shell/001-help.sh +0 -2
  38. {cfengine-0.3.0 → cfengine-0.4.0}/.python-version +0 -0
  39. {cfengine-0.3.0 → cfengine-0.4.0}/LICENSE +0 -0
  40. {cfengine-0.3.0 → cfengine-0.4.0}/setup.cfg +0 -0
  41. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine.egg-info/dependency_links.txt +0 -0
  42. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine.egg-info/entry_points.txt +0 -0
  43. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine.egg-info/top_level.txt +0 -0
  44. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/__init__.py +0 -0
  45. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/__main__.py +0 -0
  46. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/paths.py +0 -0
  47. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/shell.py +0 -0
  48. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/utils.py +0 -0
  49. {cfengine-0.3.0 → cfengine-0.4.0}/src/cfengine_cli/version.py +0 -0
  50. {cfengine-0.3.0 → cfengine-0.4.0}/tests/__init__.py +0 -0
  51. {cfengine-0.3.0 → cfengine-0.4.0}/tests/test_deps.py +0 -0
@@ -7,3 +7,11 @@ updates:
7
7
  directory: "/"
8
8
  schedule:
9
9
  interval: "weekly"
10
+ prefix: "pip"
11
+ - package-ecosystem: "github-actions"
12
+ directory: "/"
13
+ schedule:
14
+ interval: "weekly"
15
+ reviewers:
16
+ - "olehermanse"
17
+ prefix: "GitHub Actions"
@@ -9,6 +9,9 @@ on:
9
9
  pull_request:
10
10
  branches: [main]
11
11
 
12
+ permissions:
13
+ contents: read
14
+
12
15
  jobs:
13
16
  check:
14
17
  runs-on: ubuntu-22.04
@@ -1,5 +1,9 @@
1
1
  name: Automatically format with Black and submit PR
2
2
 
3
+ permissions:
4
+ contents: read
5
+ pull-requests: write
6
+
3
7
  on:
4
8
  push:
5
9
  branches:
@@ -0,0 +1,60 @@
1
+ # Taken from GH docs:
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ release-build:
9
+ runs-on: ubuntu-24.04
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.x"
20
+
21
+ - name: Build release distributions
22
+ run: |
23
+ git fetch --all --tags
24
+ python -m pip install pip
25
+ pip install uv
26
+ uv lock --check
27
+ uv build
28
+
29
+ - name: Upload release-dists as artifact
30
+ uses: actions/upload-artifact@v4
31
+ with:
32
+ name: release-dists
33
+ path: dist/
34
+
35
+ # pre-release-tests:
36
+ # runs-on: ubuntu-24.04
37
+ #
38
+ # permissions:
39
+ # contents: read
40
+ #
41
+ # steps:
42
+ # - uses: actions/checkout@v4
43
+ # - uses: ./.github/workflows/tests.yml
44
+
45
+ pypi-publish:
46
+ runs-on: ubuntu-24.04
47
+ needs:
48
+ - release-build
49
+ permissions:
50
+ id-token: write
51
+
52
+ steps:
53
+ - name: Retrieve release distributions
54
+ uses: actions/download-artifact@v4
55
+ with:
56
+ name: release-dists
57
+ path: dist/
58
+
59
+ - name: Publish release distributions to PyPI
60
+ uses: pypa/gh-action-pypi-publish@v1.12.4
@@ -0,0 +1,31 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3
+
4
+ name: Tests
5
+
6
+ on:
7
+ push:
8
+ branches: [main]
9
+ pull_request:
10
+ branches: [main]
11
+ workflow_call:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ all-tests:
18
+ runs-on: ubuntu-22.04
19
+ strategy:
20
+ fail-fast: true
21
+ matrix:
22
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
23
+
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ with:
27
+ fetch-depth: 0
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ uses: actions/setup-python@v5
30
+ with:
31
+ python-version: ${{ matrix.python-version }}
@@ -6,4 +6,5 @@ venv
6
6
  .venv
7
7
  __pycache__
8
8
  .DS_STORE
9
- .pytest_cache
9
+ .pytest_cache
10
+ /out/
@@ -44,8 +44,13 @@ If it does not work, click the failing GitHub Actions and try to understand what
44
44
  The process is virtually identical to using the GUI.
45
45
  Once you've determined what the version number should be, use the `gh release create`, and answer the prompts in a similar way to above:
46
46
 
47
+ ```bash
48
+ gh release create
49
+ ```
50
+
51
+ Go through the prompts:
52
+
47
53
  ```
48
- $ gh release create
49
54
  ? Choose a tag Create a new tag
50
55
  ? Tag name 0.2.0
51
56
  ? Title (optional) 0.2.0
@@ -53,7 +58,6 @@ $ gh release create
53
58
  ? Is this a prerelease? No
54
59
  ? Submit? Publish release
55
60
  https://github.com/cfengine/cfengine-cli/releases/tag/0.2.0
56
- $
57
61
  ```
58
62
 
59
63
  Then check that everything went well;
@@ -83,6 +87,57 @@ For simplicity's sake, we don't have a custom configuration, we use the tool's d
83
87
 
84
88
  If your editor does not do this automatically, you can run these tools from the command line:
85
89
 
86
- ```
90
+ ```bash
87
91
  black . && prettier . --write
88
92
  ```
93
+
94
+ ## Running commands during development
95
+
96
+ This project uses `uv`.
97
+ This makes it easy to run commands without installing the project, for example:
98
+
99
+ ```bash
100
+ uv run cfengine format
101
+ ```
102
+
103
+ ## Installing from source:
104
+
105
+ ```bash
106
+ git fetch --all --tags
107
+ pip3 install .
108
+ ```
109
+
110
+ ## Running tests
111
+
112
+ Unit tests:
113
+
114
+ ```bash
115
+ py.test
116
+ ```
117
+
118
+ Shell tests (requires installing first):
119
+
120
+ ```bash
121
+ cat tests/shell/*.sh | bash
122
+ ```
123
+
124
+ ## Not implemented yet / TODOs
125
+
126
+ - `cfengine run`
127
+ - The command could automatically detect that you have CFEngine installed on a remote hub, and run it there instead (using `cf-remote`).
128
+ - Handle when `cf-agent` is not installed, help users install.
129
+ - Prompt / help users do what they meant (i.e. build and deploy and run).
130
+ - `cfengine format`
131
+ - Automatically break up and indent method calls, function calls, and nested function calls.
132
+ - Smarter placement of comments based on context.
133
+ - The command should be able to take a filename as an argument, and also operate using stdin and stdout.
134
+ (Receive file content on stdin, file type using command line arg, output formatted file to stdout).
135
+ - We can add a shortcut, `cfengine fmt`, since that matches other tools, like `deno`.
136
+ - `cfengine lint`
137
+ - The command should be able to take a filename as an argument, and also take file content from stdin.
138
+ - It would be nice if we refactored `validate_config()` in `cfbs` so it would take a simple dictionary (JSON) instead of a special CFBSConfig object.
139
+ - Missing commands:
140
+ - `cfengine install` - Install CFEngine packages / binaries (Wrapping `cf-remote install`).
141
+ - `cfengine dev` - Subcommand for CFEngine developers / maintainers.
142
+ - `cfengine dev release-information` - Generate release information (Wrapping `cfbs generate-release-information`)
143
+ - `cfengine dev dependency-tables` - Update dependency tables in markdown files.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: cfengine
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Human-oriented CLI for interacting with CFEngine tools
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -691,12 +691,14 @@ Classifier: Programming Language :: Python :: 3.10
691
691
  Classifier: Programming Language :: Python :: 3.11
692
692
  Classifier: Programming Language :: Python :: 3.12
693
693
  Classifier: Programming Language :: Python :: 3.13
694
- Classifier: Programming Language :: Python :: 3.14
695
694
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
696
695
  Requires-Python: >=3.9
697
696
  Description-Content-Type: text/markdown
698
697
  Requires-Dist: cf-remote>=0.6.4
699
- Requires-Dist: cfbs>=4.3.1
698
+ Requires-Dist: cfbs>=4.4.2
699
+ Requires-Dist: tree-sitter-cfengine>=1.0.8
700
+ Requires-Dist: tree-sitter>=0.23
701
+ Requires-Dist: markdown-it-py>=3.0.0
700
702
 
701
703
  # CFEngine command line interface (CLI)
702
704
 
@@ -711,27 +713,58 @@ Proceed with caution and excitement.
711
713
 
712
714
  Install using pip:
713
715
 
714
- ```
716
+ ```bash
715
717
  pip install cfengine
716
718
  ```
717
719
 
718
720
  ## Usage
719
721
 
720
- To perform an agent run:
722
+ ### Run the CFEngine agent - evaluate and enforce policy
723
+
724
+ ```bash
725
+ cfengine run
726
+ ```
727
+
728
+ ### CFEngine CLI help
721
729
 
730
+ ```bash
731
+ cfengine help
722
732
  ```
733
+
734
+ ### Print CFEngine CLI version
735
+
736
+ ```bash
723
737
  cfengine run
724
738
  ```
725
739
 
726
- To get additional help:
740
+ ### Automatically format source code
727
741
 
742
+ ```bash
743
+ cfengine format
728
744
  ```
729
- cfengine help
745
+
746
+ ### Check for errors in source code
747
+
748
+ ```bash
749
+ cfengine lint
750
+ ```
751
+
752
+ Note that since we use a different parser than `cf-agent` / `cf-promises`, they are not 100% in sync.
753
+ `cf-agent` could point out something as a syntax error, while `cfengine lint` does not and vice versa.
754
+ We aim to make the tree-sitter parser (used in this tool) more strict in general, so that when `cfengine lint` is happy with your policy, `cf-agent` will also accept it.
755
+ (But the opposite is not a goal, that `cfengine lint` must accept any policy `cf-agent` would find acceptable).
756
+
757
+ ### Build a policy set
758
+
759
+ ```bash
760
+ cfengine build
730
761
  ```
731
762
 
763
+ (This is equivalent to running `cfbs build`).
764
+
732
765
  ## Supported platforms and versions
733
766
 
734
- This tool will only support a limited number of platforms, it is not int.
767
+ This tool will only support a limited number of platforms, it is not intended to run everywhere CFEngine runs.
735
768
  Currently we are targeting:
736
769
 
737
770
  - Officially supported versions of macOS, Ubuntu, and Fedora.
@@ -11,27 +11,58 @@ Proceed with caution and excitement.
11
11
 
12
12
  Install using pip:
13
13
 
14
- ```
14
+ ```bash
15
15
  pip install cfengine
16
16
  ```
17
17
 
18
18
  ## Usage
19
19
 
20
- To perform an agent run:
20
+ ### Run the CFEngine agent - evaluate and enforce policy
21
+
22
+ ```bash
23
+ cfengine run
24
+ ```
25
+
26
+ ### CFEngine CLI help
21
27
 
28
+ ```bash
29
+ cfengine help
22
30
  ```
31
+
32
+ ### Print CFEngine CLI version
33
+
34
+ ```bash
23
35
  cfengine run
24
36
  ```
25
37
 
26
- To get additional help:
38
+ ### Automatically format source code
27
39
 
40
+ ```bash
41
+ cfengine format
28
42
  ```
29
- cfengine help
43
+
44
+ ### Check for errors in source code
45
+
46
+ ```bash
47
+ cfengine lint
48
+ ```
49
+
50
+ Note that since we use a different parser than `cf-agent` / `cf-promises`, they are not 100% in sync.
51
+ `cf-agent` could point out something as a syntax error, while `cfengine lint` does not and vice versa.
52
+ We aim to make the tree-sitter parser (used in this tool) more strict in general, so that when `cfengine lint` is happy with your policy, `cf-agent` will also accept it.
53
+ (But the opposite is not a goal, that `cfengine lint` must accept any policy `cf-agent` would find acceptable).
54
+
55
+ ### Build a policy set
56
+
57
+ ```bash
58
+ cfengine build
30
59
  ```
31
60
 
61
+ (This is equivalent to running `cfbs build`).
62
+
32
63
  ## Supported platforms and versions
33
64
 
34
- This tool will only support a limited number of platforms, it is not int.
65
+ This tool will only support a limited number of platforms, it is not intended to run everywhere CFEngine runs.
35
66
  Currently we are targeting:
36
67
 
37
68
  - Officially supported versions of macOS, Ubuntu, and Fedora.
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -x
5
+
6
+ pipx install uv
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -x
5
+
6
+ uv lock --check
7
+ uv run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
8
+ uv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
9
+ uv run pytest
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -x
5
+
6
+ uv lock --check
7
+ uv build
8
+ pip install .
9
+ cfengine --version
10
+ bash tests/docker/0*.sh
11
+ bash tests/shell/0*.sh
@@ -11,7 +11,10 @@ license = {file = "LICENSE"}
11
11
  requires-python = ">=3.9"
12
12
  dependencies = [
13
13
  "cf-remote>=0.6.4",
14
- "cfbs>=4.3.1",
14
+ "cfbs>=4.4.2",
15
+ "tree-sitter-cfengine>=1.0.8",
16
+ "tree-sitter>=0.23",
17
+ "markdown-it-py>=3.0.0",
15
18
  ]
16
19
  classifiers = [
17
20
  "Development Status :: 3 - Alpha",
@@ -28,7 +31,6 @@ classifiers = [
28
31
  "Programming Language :: Python :: 3.11",
29
32
  "Programming Language :: Python :: 3.12",
30
33
  "Programming Language :: Python :: 3.13",
31
- "Programming Language :: Python :: 3.14",
32
34
  "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
33
35
  ]
34
36
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: cfengine
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Human-oriented CLI for interacting with CFEngine tools
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -691,12 +691,14 @@ Classifier: Programming Language :: Python :: 3.10
691
691
  Classifier: Programming Language :: Python :: 3.11
692
692
  Classifier: Programming Language :: Python :: 3.12
693
693
  Classifier: Programming Language :: Python :: 3.13
694
- Classifier: Programming Language :: Python :: 3.14
695
694
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
696
695
  Requires-Python: >=3.9
697
696
  Description-Content-Type: text/markdown
698
697
  Requires-Dist: cf-remote>=0.6.4
699
- Requires-Dist: cfbs>=4.3.1
698
+ Requires-Dist: cfbs>=4.4.2
699
+ Requires-Dist: tree-sitter-cfengine>=1.0.8
700
+ Requires-Dist: tree-sitter>=0.23
701
+ Requires-Dist: markdown-it-py>=3.0.0
700
702
 
701
703
  # CFEngine command line interface (CLI)
702
704
 
@@ -711,27 +713,58 @@ Proceed with caution and excitement.
711
713
 
712
714
  Install using pip:
713
715
 
714
- ```
716
+ ```bash
715
717
  pip install cfengine
716
718
  ```
717
719
 
718
720
  ## Usage
719
721
 
720
- To perform an agent run:
722
+ ### Run the CFEngine agent - evaluate and enforce policy
723
+
724
+ ```bash
725
+ cfengine run
726
+ ```
727
+
728
+ ### CFEngine CLI help
721
729
 
730
+ ```bash
731
+ cfengine help
722
732
  ```
733
+
734
+ ### Print CFEngine CLI version
735
+
736
+ ```bash
723
737
  cfengine run
724
738
  ```
725
739
 
726
- To get additional help:
740
+ ### Automatically format source code
727
741
 
742
+ ```bash
743
+ cfengine format
728
744
  ```
729
- cfengine help
745
+
746
+ ### Check for errors in source code
747
+
748
+ ```bash
749
+ cfengine lint
750
+ ```
751
+
752
+ Note that since we use a different parser than `cf-agent` / `cf-promises`, they are not 100% in sync.
753
+ `cf-agent` could point out something as a syntax error, while `cfengine lint` does not and vice versa.
754
+ We aim to make the tree-sitter parser (used in this tool) more strict in general, so that when `cfengine lint` is happy with your policy, `cf-agent` will also accept it.
755
+ (But the opposite is not a goal, that `cfengine lint` must accept any policy `cf-agent` would find acceptable).
756
+
757
+ ### Build a policy set
758
+
759
+ ```bash
760
+ cfengine build
730
761
  ```
731
762
 
763
+ (This is equivalent to running `cfbs build`).
764
+
732
765
  ## Supported platforms and versions
733
766
 
734
- This tool will only support a limited number of platforms, it is not int.
767
+ This tool will only support a limited number of platforms, it is not intended to run everywhere CFEngine runs.
735
768
  Currently we are targeting:
736
769
 
737
770
  - Officially supported versions of macOS, Ubuntu, and Fedora.
@@ -3,7 +3,6 @@
3
3
  HACKING.md
4
4
  LICENSE
5
5
  README.md
6
- main.py
7
6
  pyproject.toml
8
7
  uv.lock
9
8
  .github/dependabot.yml
@@ -11,6 +10,9 @@ uv.lock
11
10
  .github/workflows/black-format.yml
12
11
  .github/workflows/pypi-publish.yml
13
12
  .github/workflows/tests.yml
13
+ ci/01-install.sh
14
+ ci/02-safe-tests.sh
15
+ ci/03-unsafe-tests.sh
14
16
  src/cfengine.egg-info/PKG-INFO
15
17
  src/cfengine.egg-info/SOURCES.txt
16
18
  src/cfengine.egg-info/dependency_links.txt
@@ -20,6 +22,11 @@ src/cfengine.egg-info/top_level.txt
20
22
  src/cfengine_cli/__init__.py
21
23
  src/cfengine_cli/__main__.py
22
24
  src/cfengine_cli/commands.py
25
+ src/cfengine_cli/dependency_tables.py
26
+ src/cfengine_cli/dev.py
27
+ src/cfengine_cli/docs_formatting.py
28
+ src/cfengine_cli/format.py
29
+ src/cfengine_cli/lint.py
23
30
  src/cfengine_cli/main.py
24
31
  src/cfengine_cli/paths.py
25
32
  src/cfengine_cli/shell.py
@@ -27,6 +34,8 @@ src/cfengine_cli/utils.py
27
34
  src/cfengine_cli/version.py
28
35
  tests/__init__.py
29
36
  tests/test_deps.py
30
- tests/docker/001-docker-install-test.sh
31
- tests/docker/Dockerfile
32
- tests/shell/001-help.sh
37
+ tests/test_paths.py
38
+ tests/test_utils.py
39
+ tests/test_version.py
40
+ tests/shell/001-help.sh
41
+ tests/shell/002-version.sh
@@ -0,0 +1,5 @@
1
+ cf-remote>=0.6.4
2
+ cfbs>=4.4.2
3
+ tree-sitter-cfengine>=1.0.8
4
+ tree-sitter>=0.23
5
+ markdown-it-py>=3.0.0
@@ -0,0 +1,96 @@
1
+ import os
2
+ from cfengine_cli.dev import dispatch_dev_subcommand
3
+ from cfengine_cli.lint import lint_cfbs_json, lint_json, lint_policy_file
4
+ from cfengine_cli.shell import user_command
5
+ from cfengine_cli.paths import bin
6
+ from cfengine_cli.version import cfengine_cli_version_string
7
+ from cfengine_cli.format import format_policy_file, format_json_file
8
+ from cfengine_cli.utils import UserError
9
+ from cfbs.utils import find
10
+ from cfbs.commands import build_command
11
+ from cf_remote.commands import deploy as deploy_command
12
+
13
+
14
+ def _require_cfagent():
15
+ if not os.path.exists(bin("cf-agent")):
16
+ raise UserError(f"cf-agent not found at {bin('cf-agent')}")
17
+
18
+
19
+ def _require_cfhub():
20
+ if not os.path.exists(bin("cf-hub")):
21
+ raise UserError(f"cf-hub not found at {bin('cf-hub')}")
22
+
23
+
24
+ def help() -> int:
25
+ print("Example usage:")
26
+ print("cfengine run")
27
+ return 0
28
+
29
+
30
+ def version() -> int:
31
+ print(cfengine_cli_version_string())
32
+ return 0
33
+
34
+
35
+ def build() -> int:
36
+ r = build_command()
37
+ if r is None:
38
+ # Workaround for https://github.com/cfengine/cfbs/pull/231
39
+ return 0
40
+ return r
41
+
42
+
43
+ def deploy() -> int:
44
+ r = deploy_command(None, None)
45
+ return r
46
+
47
+
48
+ def format() -> int:
49
+ for filename in find(".", extension=".json"):
50
+ if filename.startswith("./."):
51
+ continue
52
+ format_json_file(filename)
53
+ for policy_file in find(".", extension=".cf"):
54
+ if policy_file.startswith("./."):
55
+ continue
56
+ format_policy_file(policy_file)
57
+ return 0
58
+
59
+
60
+ def lint() -> int:
61
+ errors = 0
62
+ for filename in find(".", extension=".json"):
63
+ if filename.startswith(("./.", "./out/")):
64
+ continue
65
+ if filename.endswith("/cfbs.json"):
66
+ lint_cfbs_json(filename)
67
+ continue
68
+ errors += lint_json(filename)
69
+
70
+ for filename in find(".", extension=".cf"):
71
+ if filename.startswith(("./.", "./out/")):
72
+ continue
73
+ errors += lint_policy_file(filename)
74
+
75
+ if errors == 0:
76
+ return 0
77
+ return 1
78
+
79
+
80
+ def report() -> int:
81
+ _require_cfhub()
82
+ _require_cfagent()
83
+ user_command(f"{bin('cf-agent')} -KIf update.cf && {bin('cf-agent')} -KI")
84
+ user_command(f"{bin('cf-hub')} --query rebase -H 127.0.0.1")
85
+ user_command(f"{bin('cf-hub')} --query delta -H 127.0.0.1")
86
+ return 0
87
+
88
+
89
+ def run() -> int:
90
+ _require_cfagent()
91
+ user_command(f"{bin('cf-agent')} -KIf update.cf && {bin('cf-agent')} -KI")
92
+ return 0
93
+
94
+
95
+ def dev(subcommand) -> int:
96
+ return dispatch_dev_subcommand(subcommand)
@@ -0,0 +1,2 @@
1
+ def update_dependency_tables() -> int:
2
+ return 0