├── .coveragerc ├── .coveragerc-behave ├── .dockerignore ├── .gherkin-lintrc ├── .github └── dependabot.yml ├── .gitignore ├── .gitlab-ci.yml ├── .markdownlint-changelog.json ├── .markdownlint.json ├── .pylintrc ├── .travis.yml ├── .vulture-whitelist.py ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── ci ├── behave.sh ├── docs.sh ├── quality.sh ├── release.sh ├── security.sh ├── sonarcloud-scanner.sh ├── sonarqube-scanner.sh ├── sonarqube_token.py └── unittest.sh ├── docker-compose.yml ├── docs ├── .next-action.cfg ├── README.in.md ├── classes.png ├── demo.gif ├── dependencies.png ├── packages.png ├── todo.txt └── update_readme.py ├── extra └── .next-action-completion.bash ├── next_action ├── __init__.py ├── arguments │ ├── __init__.py │ ├── config.py │ └── parser.py ├── output │ ├── __init__.py │ ├── color.py │ ├── reference.py │ ├── url.py │ └── warning.py ├── pick_action.py └── todotxt │ ├── __init__.py │ ├── task.py │ └── tasks.py ├── renovate.json ├── requirements-dev.txt ├── requirements.txt ├── setup.cfg ├── setup.py ├── sonar-project.properties └── tests ├── __init__.py ├── create_random_todo_txt.py ├── features ├── completion.feature ├── context.feature ├── dependencies.feature ├── due.feature ├── environment.py ├── error.feature ├── file.feature ├── generate_config.feature ├── groupby.feature ├── nothing_to_do.feature ├── number.feature ├── priority.feature ├── project.feature ├── reference.feature ├── steps │ ├── config.py │ ├── show_next_action.py │ └── version.py ├── style.feature ├── url.feature ├── validate_config.feature └── version.feature └── unittests ├── __init__.py ├── arguments ├── __init__.py ├── test_config.py └── test_parser.py ├── fixtures.py ├── output ├── __init__.py ├── test_color.py ├── test_reference.py ├── test_render.py ├── test_url.py └── test_warning.py ├── test_cli.py ├── test_pick_action.py └── todotxt ├── __init__.py ├── test_read_todotxt_files.py ├── test_task.py └── test_tasks.py /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | .venv/*/** 4 | 5 | [report] 6 | # Regexes for lines to exclude from consideration 7 | exclude_lines = 8 | pragma: no cover 9 | pragma: no cover-behave 10 | def __repr__ 11 | raise NotImplementedError 12 | 13 | -------------------------------------------------------------------------------- /.coveragerc-behave: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | /usr/local/bin/next-action 4 | .venv/**/* 5 | 6 | [report] 7 | # Regexes for lines to exclude from consideration 8 | exclude_lines = 9 | pragma: no cover 10 | pragma: no cover-behave 11 | def __repr__ 12 | raise NotImplementedError 13 | 14 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .git/ 3 | .gitignore 4 | .hypothesis/ 5 | .mypy_cache/ 6 | .owasp-dependency-check-data 7 | .scannerwork/ 8 | .sonarlint/ 9 | .venv/ 10 | .vscode/ 11 | build/ 12 | dist/ 13 | -------------------------------------------------------------------------------- /.gherkin-lintrc: -------------------------------------------------------------------------------- 1 | { 2 | "no-files-without-scenarios": "on", 3 | "no-unnamed-features": "on", 4 | "no-unnamed-scenarios": "on", 5 | "no-dupe-scenario-names": "on", 6 | "no-dupe-feature-names": "on", 7 | "no-partially-commented-tag-lines": "on", 8 | "indentation": [ 9 | "on", 10 | { 11 | "Background": 2, 12 | "Scenario": 2, 13 | "Step": 4 14 | } 15 | ], 16 | "no-trailing-spaces": "on", 17 | "new-line-at-eof": [ 18 | "on", 19 | "yes" 20 | ], 21 | "no-multiple-empty-lines": "on", 22 | "no-empty-file": "on", 23 | "no-scenario-outlines-without-examples": "on", 24 | "name-length": [ 25 | "on", 26 | { 27 | "Feature": 100, 28 | "Scenario": 100, 29 | "Step": 120 30 | } 31 | ], 32 | "no-restricted-tags": [ 33 | "on", 34 | { 35 | "tags": [ 36 | "@watch", 37 | "@wip" 38 | ] 39 | } 40 | ], 41 | "use-and": "on", 42 | "no-duplicate-tags": "on", 43 | "no-superfluous-tags": "on", 44 | "no-homogenous-tags": "on", 45 | "one-space-between-tags": "on", 46 | "no-unused-variables": "on", 47 | "no-background-only-scenario": "on", 48 | "no-empty-background": "on" 49 | } 50 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "pip" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.py[cod] 3 | .coverage* 4 | !.coveragerc* 5 | .mypy_cache 6 | .sonarlint 7 | .scannerwork 8 | .vscode 9 | .DS_Store 10 | build 11 | coverage.xml 12 | dist 13 | venv 14 | *.egg-info 15 | .idea 16 | .venv 17 | .hypothesis 18 | .tox 19 | .owasp-dependency-check-data 20 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: fniessink/next-action-dev:latest 2 | 3 | variables: 4 | # When using dind service we need to instruct docker, to talk with the 5 | # daemon started inside of the service. The daemon is available with 6 | # a network connection instead of the default /var/run/docker.sock socket. 7 | # 8 | # The 'docker' hostname is the alias of the service container as described at 9 | # https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services 10 | # 11 | # Note that if you're using Kubernetes executor, the variable should be set to 12 | # tcp://localhost:2375 because of how Kubernetes executor connects services 13 | # to the job container 14 | DOCKER_HOST: tcp://docker:2375/ 15 | # When using dind, it's wise to use the overlayfs driver for 16 | # improved performance. 17 | DOCKER_DRIVER: overlay2 18 | 19 | services: 20 | - docker:dind 21 | 22 | unittest: 23 | stage: test 24 | script: docker-compose up unittest 25 | coverage: '/ \d+%/' 26 | artifacts: 27 | paths: 28 | - build/unittest-coverage 29 | 30 | behave: 31 | stage: test 32 | script: docker-compose up behave 33 | coverage: '/ \d+%/' 34 | artifacts: 35 | paths: 36 | - build/feature-coverage 37 | 38 | security: 39 | stage: test 40 | script: docker-compose up security 41 | artifacts: 42 | paths: 43 | - build/bandit.html 44 | 45 | quality: 46 | stage: test 47 | script: docker-compose up quality 48 | artifacts: 49 | paths: 50 | - build/mypy 51 | 52 | docs: 53 | stage: test 54 | script: docker-compose up docs 55 | artifacts: 56 | paths: 57 | - build/README.html 58 | -------------------------------------------------------------------------------- /.markdownlint-changelog.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ".markdownlint.json", 3 | "MD024": false 4 | } 5 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD013": {"line_length": 120} 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | services: 2 | - docker 3 | language: python 4 | install: 5 | - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 6 | - docker pull fniessink/next-action-dev:latest 7 | script: 8 | - docker compose up --exit-code-from docs docs 9 | - docker compose up sonarcloud-scanner 10 | deploy: 11 | provider: script 12 | script: docker compose up release 13 | on: 14 | tags: true 15 | -------------------------------------------------------------------------------- /.vulture-whitelist.py: -------------------------------------------------------------------------------- 1 | """False positive whitelist for Vulture.""" 2 | # pylint: disable=all 3 | 4 | next_action # unused function (next_action/__init__.py:17) 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [1.13.0] - 2020-05-25 9 | 10 | ### Added 11 | 12 | - Allow for adding line numbers to next actions using the `--line-number` command line argument. Closes #712. 13 | 14 | ## [1.12.0] - 2019-11-17 15 | 16 | ### Added 17 | 18 | - Allow for opening URLs in next actions using the `--open-urls` command line argument. Closes #577. 19 | 20 | ## [1.11.2] - 2019-05-18 21 | 22 | ### Changed 23 | 24 | - Updated dependencies. 25 | 26 | ## [1.11.1] - 2018-11-15 27 | 28 | ### Fixed 29 | 30 | - Allow for using the `groupby` option without argument to override a configured `groupby` option. Fixes #335. 31 | 32 | ## [1.11.0] - 2018-11-14 33 | 34 | ### Added 35 | 36 | - Allow for hiding tasks with `h:1`. Closes #332. 37 | 38 | ## [1.10.0] - 2018-11-14 39 | 40 | ### Added 41 | 42 | - Allow for grouping tasks by context, project, due date, priority or source file. Closes #324. 43 | 44 | ### Removed 45 | 46 | - Removed time travel feature as it's not very useful. 47 | 48 | ## [1.9.0] - 2018-10-20 49 | 50 | ### Added 51 | 52 | - Show 😴 emoji when there's nothing to do. Closes #256. 53 | 54 | ## [1.8.1] - 2018-09-07 55 | 56 | ### Fixed 57 | 58 | - Prevent @ from being escaped when using tab completion. Fixes #249. 59 | - Don't consider brackets being part of context or project names. Fixes #245. 60 | 61 | ## [1.8.0] - 2018-09-06 62 | 63 | ### Added 64 | 65 | - Tab completion for the *Next-action* command line interface in Bash. Closes #228. 66 | 67 | ### Fixed 68 | 69 | - Allow for projects and contexts at the start of a line. Fixes #242. 70 | 71 | ## [1.7.2] - 2018-08-26 72 | 73 | ### Fixed 74 | 75 | - Add option `-V` as short alternative for `--version`. Fixes #225. 76 | 77 | ## [1.7.1] - 2018-08-26 78 | 79 | ### Changed 80 | 81 | - Several performance improvements. 82 | 83 | ## [1.7.0] - 2018-08-23 84 | 85 | ### Added 86 | 87 | - Allow for time travel using the `--time-travel` option. Closes #206. 88 | 89 | ### Changed 90 | 91 | - Several performance improvements. 92 | 93 | ## [1.6.1] - 2018-08-10 94 | 95 | ### Fixed 96 | 97 | - Allow for putting the `--blocked` option in the configuration file. Fixes #204. 98 | 99 | ## [1.6.0] - 2018-08-07 100 | 101 | ### Added 102 | 103 | - Show tasks blocked by the next action using the `--blocked` option. Closes #166. 104 | 105 | ### Fixed 106 | 107 | - Give proper error message when the `--number` argument is smaller than one. Fixes #164. 108 | 109 | ## [1.5.3] - 2018-07-14 110 | 111 | ### Fixed 112 | 113 | - Allow for using `--config` when generating a configuration file with `--write-config-file` so it is possible to 114 | ignore the existing configuration file when generating a new one. Fixes #161. 115 | 116 | ## [1.5.2] - 2018-07-07 117 | 118 | ### Fixed 119 | 120 | - Add support for Python 3.7. 121 | 122 | ## [1.5.1] - 2018-07-01 123 | 124 | ### Fixed 125 | 126 | - When generating a configuration file with `--write-config-file` also include context and project filters passed on 127 | the command-line. Fixes #141. 128 | - When generating a configuration file with `--write-config-file` also include the minimum priority if passed on the 129 | command-line. Fixes #142. 130 | - Accept other arguments after excluded contexts and projects. Fixes #143. 131 | 132 | ## [1.5.0] - 2018-06-30 133 | 134 | ### Added 135 | 136 | - When generating a configuration file with `--write-config-file` add any other options on the command-line to the 137 | generated configuration file. Closes #78. 138 | 139 | ## [1.4.0] - 2018-06-25 140 | 141 | ### Added 142 | 143 | - Tasks are considered to have a priority that's the maximum of their own priority and the priorities of the task(s) 144 | they block, recursively. Closes #114. 145 | - Tasks are considered to have a due date that's the minimum of their own due date and the due dates of the task(s) 146 | they block, recursively. Closes #115. 147 | 148 | ## [1.3.0] - 2018-06-19 149 | 150 | ### Added 151 | 152 | - Next to `p:parent_task` it's also possible to use `before:parent_task` to specifiy task dependencies. 153 | - In addition to `before:other_task`, it's also possible to use `after:other_task` to specify task dependencies. 154 | 155 | ## [1.2.0] - 2018-06-16 156 | 157 | ### Added 158 | 159 | - Warn user if there are no next actions because they are using contexts or projects not present in the todo.txt file. 160 | 161 | ## [1.1.0] - 2018-06-11 162 | 163 | ### Added 164 | 165 | - Take task dependencies into account. Closes #101. 166 | 167 | ## [1.0.0] - 2018-06-09 168 | 169 | ### Added 170 | 171 | - Default context and/or project filters can be configured in the configuration file. Closes #109. 172 | 173 | ## [0.17.0] - 2018-06-07 174 | 175 | ### Added 176 | 177 | - Support threshold dates (`t:`) in todo.txt files. 178 | 179 | ## [0.16.3] - 2018-06-05 180 | 181 | ### Fixed 182 | 183 | - Capitalise the help information. Fixes #105. 184 | 185 | ## [0.16.2] - 2018-06-05 186 | 187 | ### Fixed 188 | 189 | - Mention how to deal with options with optional arguments followed by positional arguments in the help information 190 | and README. Closes #100. 191 | - Short options immediately followed by a value weren't parsed correctly. Fixes #84. 192 | 193 | ## [0.16.1] - 2018-06-04 194 | 195 | ### Fixed 196 | 197 | - Include reference parameter into standard configuration file. Fixes #98. 198 | 199 | ## [0.16.0] - 2018-06-03 200 | 201 | ### Added 202 | 203 | - Optionally reference the todo.txt filename from which the next actions were read. Closes #38. 204 | 205 | ### Changed 206 | 207 | - Reorganized the help information. 208 | 209 | ## [0.15.0] - 2018-06-02 210 | 211 | ### Added 212 | 213 | - The due date argument to `--due` is now optional. Closes #92. 214 | 215 | ## [0.14.1] - 2018-06-01 216 | 217 | ### Fixed 218 | 219 | - Fix packaging. 220 | 221 | ## [0.14.0] - 2018-06-01 222 | 223 | ### Added 224 | 225 | - Option to limit the next action to tasks that have a given due date. Closes #53. 226 | 227 | ## [0.13.0] - 2018-05-30 228 | 229 | ### Added 230 | 231 | - Using the `--style` option without arguments ignores the style specified in the configuration file, if any. 232 | Closes #83. 233 | 234 | ### Changed 235 | 236 | - The `--no-config-file` option was removed. To not read any configuration file, use the `--config-file` option without 237 | specifying a configuration filename. Closes #82. 238 | 239 | ## [0.12.0] - 2018-05-28 240 | 241 | ### Added 242 | 243 | - Option to limit the next action to tasks with a minimum priority. Closes #80. 244 | 245 | ### Fixed 246 | 247 | - Properly wrap the usage line of the help information. Fixes #81. 248 | 249 | ## [0.11.0] - 2018-05-27 250 | 251 | ### Changed 252 | 253 | - Better error messages when the configuration file is invalid. 254 | 255 | ## [0.10.1] - 2018-05-27 256 | 257 | ### Fixed 258 | 259 | - Setup.py and requirements.txt were inconsistent. 260 | 261 | ## [0.10.0] - 2018-05-27 262 | 263 | ### Added 264 | 265 | - Coloring of output using Pygments. Closes #11. 266 | 267 | ## [0.9.0] - 2018-05-25 268 | 269 | ### Added 270 | 271 | - Option to limit the next action to tasks that are over due. Closes #75. 272 | 273 | ## [0.8.0] - 2018-05-24 274 | 275 | ### Added 276 | 277 | - Option to not read a configuration file. Closes #71. 278 | - Option to write a default configuration file. Closes #68. 279 | 280 | ## [0.7.0] - 2018-05-23 281 | 282 | ### Added 283 | 284 | - The number of next actions to show can be configured in the configuration file. Closes #65. 285 | 286 | ### Changed 287 | 288 | - Use a third-party package to validate the configuration file YAML instead of custom code. Closes #66. 289 | 290 | ## [0.6.0] - 2018-05-21 291 | 292 | ### Added 293 | 294 | - Next-action can read a configuration file in which the todo.txt file(s) to read can be specified. Closes #40. 295 | 296 | ## [0.5.2] - 2018-05-19 297 | 298 | ### Fixed 299 | 300 | - Make the demo animated gif visible on the Python Package Index. Fixes #61. 301 | 302 | ## [0.5.1] - 2018-05-19 303 | 304 | ### Added 305 | 306 | - Add the README file to the package description on the [Python Package Index](https://pypi.org/project/next-action/). 307 | Closes #59. 308 | 309 | ## [0.5.0] - 2018-05-19 310 | 311 | ### Added 312 | 313 | - Other properties being equal, task with more projects get precedence over tasks with fewer projects when selecting 314 | the next action. Closes #57. 315 | 316 | ## [0.4.0] - 2018-05-19 317 | 318 | ### Changed 319 | 320 | - If no file is specified, *Next-action* tries to read the todo.txt in the user's home folder. Closes #4. 321 | 322 | ## [0.3.0] - 2018-05-19 323 | 324 | ### Added 325 | 326 | - The `--file` argument accepts `-` to read input from standard input. Closes #42. 327 | 328 | ### Fixed 329 | 330 | - Give consistent error message when files can't be opened. Fixes #54. 331 | 332 | ## [0.2.1] - 2018-05-16 333 | 334 | ### Changed 335 | 336 | - Simpler help message. Fixes #45. 337 | 338 | ## [0.2.0] - 2018-05-14 339 | 340 | ### Added 341 | 342 | - Allow for excluding contexts from which the next action is selected: `next-action -@office`. Closes #20. 343 | - Allow for excluding projects from which the next action is selected: `next-action -+DogHouse`. Closes #32. 344 | 345 | ## [0.1.0] - 2018-05-13 346 | 347 | ### Added 348 | 349 | - Take due date into account when determining the next action. Tasks due earlier take precedence. Closes #33. 350 | 351 | ## [0.0.9] - 2018-05-13 352 | 353 | ### Added 354 | 355 | - Next-action can now read multiple todo.txt files to select the next action from. For example: 356 | `next-action --file todo.txt --file big-project-todo.txt`. Closes #35. 357 | 358 | ### Changed 359 | 360 | - Ignore tasks that have a start date in the future. Closes #34. 361 | - Take creation date into account when determining the next action. Tasks created earlier take precedence. Closes #26. 362 | 363 | ## [0.0.8] - 2018-05-13 364 | 365 | ### Added 366 | 367 | - Specify the number of next actions to show: `next-action --number 3`. Closes #7. 368 | - Show all next actions: `next-action --all`. Closes #29. 369 | 370 | ## [0.0.7] - 2018-05-12 371 | 372 | ### Added 373 | 374 | - Allow for limiting the next action to one from multiple projects: `next-action +DogHouse +PaintHouse`. Closes #27. 375 | - Allow for limiting the next action to multiple contexts: `next-action @work @staffmeeting`. Closes #23. 376 | 377 | ## [0.0.6] - 2018-05-11 378 | 379 | ### Added 380 | 381 | - Allow for limiting the next action to a specific project. Closes #6. 382 | 383 | ## [0.0.5] - 2018-05-11 384 | 385 | ### Changed 386 | 387 | - Renamed Next-action's binary from `next_action` to `next-action` for consistency with the application and project 388 | name. 389 | 390 | ## [0.0.4] - 2018-05-10 391 | 392 | ### Added 393 | 394 | - Allow for limiting the next action to a specific context. Closes #5. 395 | - Version number command line argument (`--version`) to display Next-action's version number. 396 | 397 | ### Fixed 398 | 399 | - Runing tests with "python setup.py test" would result in test failures. Fixes #15. 400 | - Move development dependencies to requirements-dev.txt so they don't get installed when a user installs Next-action. 401 | Fixes #14. 402 | - Make Travis generate a wheel distribution in addition to the source distribution. Fixes #14. 403 | 404 | ## [0.0.3] - 2018-05-10 405 | 406 | ### Fixed 407 | 408 | - Show default filename in the help message. Fixes #3. 409 | - Show friendly error message when file cannot be found. Fixes #2. 410 | 411 | ## [0.0.2] - 2018-05-09 412 | 413 | ### Changed 414 | 415 | - Release to the Python Package Index from Travis. 416 | 417 | ## [0.0.1] - 2018-05-06 418 | 419 | ### Added 420 | 421 | - `next_action` script that reads a todo.txt file and prints the next action the user should work on, based on the 422 | priorities of the tasks. 423 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM koalaman/shellcheck-alpine:v0.9.0 AS shellcheck 2 | FROM hadolint/hadolint:v2.12.0-alpine AS hadolint 3 | FROM python:3.11-alpine 4 | 5 | LABEL maintainer="Frank Niessink " 6 | LABEL description="Development dependencies for Next-action." 7 | 8 | # Hadolint wants pinned versions but that breaks the build of the Docker image on Travis 9 | # hadolint ignore=DL3018 10 | RUN apk --no-cache add musl-dev gcc make nodejs npm graphviz docker docker-compose ttf-freefont libffi-dev openjdk11 unzip sed libxml2-dev libxslt-dev openssl-dev 11 | # libffi is needed for twine, ubuntu-font-family for graphviz, openjdk11 for sonar-scanner, libxml2 for lxml 12 | 13 | ADD https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip ./package.zip 14 | RUN unzip package.zip && mv ./sonar-scanner* /sonar-scanner && ln -s /sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner && rm package.zip 15 | # Ensure Sonar uses the provided Java for musl instead of the included glibc one 16 | RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /sonar-scanner/bin/sonar-scanner 17 | 18 | COPY --from=shellcheck /bin/shellcheck /usr/local/bin/ 19 | COPY --from=hadolint /bin/hadolint /usr/local/bin/ 20 | 21 | RUN npm install -g gherkin-lint@4.2.2 markdownlint-cli@0.32.2 marked@4.2.5 22 | WORKDIR /next-action 23 | COPY requirements*.txt /next-action/ 24 | RUN pip install --no-cache-dir pip==22.3.1 && pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ci/behave.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | pip install --quiet --quiet -e . 4 | behave --format null tests/features 5 | coverage report --rcfile=.coveragerc-behave --fail-under=100 --skip-covered 6 | -------------------------------------------------------------------------------- /ci/docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | pydeps --noshow -T png -o docs/dependencies.png next_action 4 | pyreverse --module-names=yes --show-associated=1 --show-ancestors=1 --output=png next_action > /dev/null 5 | mv classes.png docs/ 6 | mv packages.png docs/ 7 | pip install --quiet --quiet -e . 8 | python docs/update_readme.py 9 | marked -i README.md -o build/README.html 10 | -------------------------------------------------------------------------------- /ci/quality.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mypy next_action 4 | pylint next_action tests docs 5 | pycodestyle next_action tests 6 | pydocstyle next_action tests 7 | vulture next_action .vulture-whitelist.py 8 | pyroma --min=10 . 9 | shellcheck extra/.next-action-completion.bash ci/*.sh 10 | gherkin-lint tests/features/*.feature 11 | markdownlint README.md docs/*.md; markdownlint -c .markdownlint-changelog.json CHANGELOG.md 12 | hadolint Dockerfile 13 | docker-compose config --quiet 14 | -------------------------------------------------------------------------------- /ci/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -rf dist 4 | python setup.py sdist bdist_wheel 5 | twine check dist/* 6 | twine upload dist/* -------------------------------------------------------------------------------- /ci/security.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | bandit -r next_action --format custom 2> /dev/null 4 | bandit -r next_action --format html --output build/bandit.html 2> /dev/null # Ignore boiler plate output 5 | safety check -r requirements.txt -r requirements-dev.txt --bare 6 | -------------------------------------------------------------------------------- /ci/sonarcloud-scanner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # SonarQube needs Xunit format, see https://docs.sonarqube.org/display/PLUG/Python+Unit+Tests+Execution+Reports+Import 4 | nosetests --nocapture --with-xunit --xunit-file=build/nosetests.xml tests/unittests 5 | sonar-scanner -Dsonar.host.url=http://sonarcloud.io -Dsonar.organization=fniessink-github -Dsonar.login="$SONAR_TOKEN" 6 | -------------------------------------------------------------------------------- /ci/sonarqube-scanner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # SonarQube needs Xunit format, see https://docs.sonarqube.org/display/PLUG/Python+Unit+Tests+Execution+Reports+Import 4 | nosetests --nocapture --with-xunit --xunit-file=build/nosetests.xml tests/unittests 5 | sonar-scanner -Dsonar.host.url="$SONARQUBE_URL" -Dsonar.login="$(python ci/sonarqube_token.py "$SONARQUBE_URL")" 6 | -------------------------------------------------------------------------------- /ci/sonarqube_token.py: -------------------------------------------------------------------------------- 1 | """Get a SonarQube token for sonar-scanner.""" 2 | 3 | import sys 4 | 5 | import requests 6 | 7 | API_URL = f"{sys.argv[1].rstrip('/')}/api/user_tokens/" 8 | API_ARGS = dict(data=dict(name="admin"), auth=("admin", "admin")) 9 | requests.post(API_URL + "revoke", **API_ARGS) # Revoke any previous tokens 10 | print(requests.post(API_URL + "generate", **API_ARGS).json()["token"]) 11 | -------------------------------------------------------------------------------- /ci/unittest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Ignore the Deprecation warning thrown by nose, see https://github.com/nose-devs/nose/issues/559 4 | python -W ignore:DeprecationWarning -m coverage run --branch -m unittest --quiet 5 | coverage xml -o build/unittest-coverage.xml 6 | coverage html --directory build/unittest-coverage 7 | coverage report --fail-under=100 --skip-covered 8 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | unittest: 4 | image: fniessink/next-action-dev:latest 5 | working_dir: ${PWD} 6 | volumes: 7 | - ${PWD}:${PWD} 8 | command: ci/unittest.sh 9 | behave: 10 | image: fniessink/next-action-dev:latest 11 | working_dir: ${PWD} 12 | volumes: 13 | - ${PWD}:${PWD} 14 | command: ci/behave.sh 15 | security: 16 | image: fniessink/next-action-dev:latest 17 | working_dir: ${PWD} 18 | volumes: 19 | - ${PWD}:${PWD} 20 | command: ci/security.sh 21 | owasp-dependency-check: 22 | image: owasp/dependency-check:latest 23 | volumes: 24 | - ${PWD}:/src 25 | - ${PWD}/.owasp-dependency-check-data:/usr/share/dependency-check/data 26 | - ${PWD}/build/owasp-dependency-check-report:/report 27 | command: /usr/share/dependency-check/bin/dependency-check.sh --scan /src --format "ALL" --project "OWASP Dependency Check" --out /src/build/owasp-dependency-check-report/ 28 | quality: 29 | image: fniessink/next-action-dev:latest 30 | working_dir: ${PWD} 31 | volumes: 32 | - ${PWD}:${PWD} 33 | command: ci/quality.sh 34 | docs: 35 | image: fniessink/next-action-dev:latest 36 | working_dir: ${PWD} 37 | volumes: 38 | - ${PWD}:${PWD} 39 | - /var/run/docker.sock:/var/run/docker.sock 40 | command: ci/docs.sh 41 | sonarcloud-scanner: 42 | image: fniessink/next-action-dev:latest 43 | working_dir: ${PWD} 44 | environment: 45 | - SONAR_TOKEN 46 | volumes: 47 | - ${PWD}:${PWD} 48 | command: ci/sonarcloud-scanner.sh 49 | sonarqube-scanner: 50 | image: fniessink/next-action-dev:latest 51 | working_dir: ${PWD} 52 | volumes: 53 | - ${PWD}:${PWD} 54 | environment: 55 | - SONARQUBE_URL=http://sonarqube:9000/ 56 | command: ci/sonarqube-scanner.sh 57 | sonarqube: 58 | image: sonarqube:latest 59 | container_name: sonarqube 60 | ports: 61 | - "9000:9000" 62 | - "9002:9002" 63 | release: 64 | image: fniessink/next-action-dev:latest 65 | working_dir: ${PWD} 66 | volumes: 67 | - ${PWD}:${PWD} 68 | command: ci/release.sh 69 | environment: 70 | - TWINE_USERNAME 71 | - TWINE_PASSWORD 72 | -------------------------------------------------------------------------------- /docs/.next-action.cfg: -------------------------------------------------------------------------------- 1 | # Configuration file for Next-action 2 | file: 3 | - docs/todo.txt 4 | -------------------------------------------------------------------------------- /docs/classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fniessink/next-action/0bf239d2b7ffe760c622e027a75d48bd1777ef37/docs/classes.png -------------------------------------------------------------------------------- /docs/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fniessink/next-action/0bf239d2b7ffe760c622e027a75d48bd1777ef37/docs/demo.gif -------------------------------------------------------------------------------- /docs/dependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fniessink/next-action/0bf239d2b7ffe760c622e027a75d48bd1777ef37/docs/dependencies.png -------------------------------------------------------------------------------- /docs/packages.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fniessink/next-action/0bf239d2b7ffe760c622e027a75d48bd1777ef37/docs/packages.png -------------------------------------------------------------------------------- /docs/todo.txt: -------------------------------------------------------------------------------- 1 | (A) Call mom @phone 2 | (B) Buy paint to +PaintHouse @store @weekend 3 | (C) Finish proposal for important client @work 4 | (G) Buy wood for new +DogHouse @store 5 | Get rid of old +DogHouse @home 6 | Borrow ladder from the neighbors +PaintHouse @home 7 | Buy flowers due:2018-02-14 8 | (L) Pay September invoice @home due:2023-09-28 9 | (K) Pay October invoice @home due:2023-10-28 10 | Buy groceries @store +DinnerParty before:meal 11 | Cook meal @home +DinnerParty id:meal due:2018-07-01 12 | Take out the garbage @home +DinnerParty due:2018-07-02 13 | Do the dishes @home +DinnerParty after:meal 14 | x This is a completed task 15 | 9999-01-01 Start preparing for five-digit years 16 | (A) Start preparing for emigration to Mars t:3000-01-01 due:3500-12-31 17 | -------------------------------------------------------------------------------- /docs/update_readme.py: -------------------------------------------------------------------------------- 1 | """Insert the output of console commands into the README.md file.""" 2 | 3 | import datetime 4 | import os 5 | import pathlib 6 | import re 7 | import shlex 8 | import subprocess # nosec 9 | import sys 10 | 11 | from asserts import assert_equal, assert_regex 12 | 13 | 14 | def do_command(line): 15 | """Run the command on the line and return its stdout and stderr.""" 16 | command = shlex.split(line[2:]) 17 | if command[0] == "next-action": 18 | command.insert(1, "--config") 19 | if "--write-config-file" not in command: 20 | command.insert(2, "docs/.next-action.cfg") 21 | output = subprocess.run( 22 | command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, check=False) # nosec 23 | return "\n".join([line.rstrip() for line in output.stdout.rstrip().split("\n")]) 24 | 25 | 26 | def create_toc(lines, toc_header, min_level=2, max_level=3): 27 | """Create the table of contents.""" 28 | result = [] 29 | for line in lines: 30 | level = line.count("#", 0, 6) 31 | if level < min_level or level > max_level or line.startswith(toc_header): 32 | continue 33 | indent = (level - min_level) * 2 34 | title = line.split(" ", 1)[1].rstrip() 35 | slug = title.lower().replace(" ", "-").replace("*", "").replace(".", "") 36 | result.append(f"{' ' * indent}- [{title}](#{slug})") 37 | return "\n".join(result) + "\n" 38 | 39 | 40 | class StateMachine: 41 | """State machine for processing the lines in the README.md. 42 | 43 | Console commands are executed and the output is inserted. The table of contents is inserted and the old 44 | table of contents is skipped. 45 | """ 46 | 47 | def __init__(self, toc, toc_header): 48 | """Initialize the state machine with the table of contents to insert and its header.""" 49 | self.toc = toc 50 | self.toc_header = toc_header 51 | self.lines = [] 52 | self.output = "" 53 | self.expected_output = "" 54 | 55 | def default(self, line): 56 | """In the default state: print the line.""" 57 | self.write_lines(line) 58 | if line == "```console": 59 | return self.in_console 60 | if line.startswith(self.toc_header): 61 | return self.start_toc 62 | return self.default 63 | 64 | def in_console(self, line): 65 | """In a console section: execute commands. Skip old output.""" 66 | if line.startswith("$ "): 67 | self.expected_output = "" # Reset the expected output 68 | self.write_lines(line) 69 | self.output = do_command(line) 70 | if self.output: 71 | self.write_lines(self.output) 72 | return self.in_console 73 | if line == "```": 74 | if self.expected_output.strip().startswith("re: "): 75 | regex = re.compile(self.expected_output[len("re: "):].strip(), re.MULTILINE) 76 | assert_regex(self.output.strip(), regex) 77 | else: 78 | assert_equal( 79 | self.expected_output.strip(), self.output.strip(), "Expected: {first}, got: {second}") 80 | self.write_lines(line) 81 | return self.default 82 | self.expected_output += "\n" + line 83 | return self.in_console 84 | 85 | def start_toc(self, line): 86 | """Start of the table of contents.""" 87 | self.write_lines(line) 88 | return self.print_toc 89 | 90 | def print_toc(self, line): 91 | """Print the table of contents.""" 92 | self.write_lines(self.toc) 93 | self.write_lines(line) 94 | return self.default 95 | 96 | def write_lines(self, line): 97 | """Write the line to the collection of lines for the README.md.""" 98 | self.lines.append(line) 99 | 100 | 101 | def update_readme(): 102 | """Read the README markdown template line by line and update table of contents and console commands.""" 103 | start = datetime.datetime.now() 104 | with open("docs/README.in.md", encoding="utf-8") as readme_in: 105 | lines = readme_in.readlines() 106 | toc_header = "## Table of contents" 107 | machine = StateMachine(create_toc(lines, toc_header), toc_header) 108 | process = machine.default 109 | for line in lines: 110 | sys.stderr.write(".") 111 | sys.stderr.flush() 112 | process = process(line.rstrip()) 113 | pathlib.Path("README.md").write_text("\n".join(machine.lines) + "\n", encoding="utf-8") 114 | duration = datetime.datetime.now() - start 115 | sys.stderr.write("\n" + "-" * 40 + f"\nProcessed {len(lines)} lines in {duration.seconds}s.\n") 116 | 117 | 118 | if __name__ == "__main__": 119 | os.environ['COLUMNS'] = "110" # Fake that the terminal is wide enough. 120 | update_readme() 121 | -------------------------------------------------------------------------------- /extra/.next-action-completion.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Following this directive would mean we divert a lot from many tab completion examples: 3 | # shellcheck disable=SC2207 4 | 5 | _next_action() 6 | { 7 | local arguments 8 | local argument_type="all" 9 | local cur=${COMP_WORDS[COMP_CWORD]} 10 | local prev=${COMP_WORDS[COMP_CWORD-1]} 11 | 12 | case ${prev} in 13 | --file|-f|--config-file|-c) 14 | COMPREPLY=( $(compgen -A "file" -- "${cur}") ) 15 | return 0 16 | ;; 17 | --priority|-p|--reference|-r|--style|-s|--time-travel|-t) 18 | argument_type=${prev} 19 | ;; 20 | *) 21 | case ${cur} in 22 | @*|+*) 23 | argument_type=${cur:0:1} 24 | ;; 25 | -@*|-+*) 26 | argument_type=${cur:0:2} 27 | ;; 28 | *) 29 | ;; 30 | esac 31 | ;; 32 | esac 33 | arguments=$(${COMP_LINE% *} --list-arguments "${argument_type//-/_}" 2> /dev/null) 34 | COMPREPLY=( $(compgen -W "${arguments}" -- "${cur}") ) 35 | return 0 36 | } 37 | shopt -u hostcomplete # Needed to prevent @ from being escaped by the readline library 38 | complete -o filenames -F _next_action next-action 39 | -------------------------------------------------------------------------------- /next_action/__init__.py: -------------------------------------------------------------------------------- 1 | """Main Next-action package.""" 2 | 3 | from .arguments import parse_arguments 4 | from .pick_action import next_actions 5 | from .output import render_next_action, render_arguments, open_urls 6 | from .todotxt import read_todotxt_files 7 | 8 | 9 | __title__ = "next-action" 10 | __version__ = "1.13.0" 11 | 12 | 13 | def next_action() -> None: 14 | """Entry point for the command-line interface. 15 | 16 | Basic recipe: 17 | 1) parse command-line arguments, 18 | 2) read todo.txt file(s), 19 | 3) determine the next action(s), 20 | 4) display them, and 21 | 5) open their urls if requested by the user. 22 | """ 23 | parser, namespace = parse_arguments(__version__) 24 | try: 25 | tasks = read_todotxt_files(namespace.file) 26 | except OSError as reason: 27 | parser.error(f"can't open file: {reason}") 28 | if namespace.list_arguments: 29 | print(render_arguments(namespace.list_arguments, tasks)) 30 | else: 31 | actions = next_actions(tasks, namespace) 32 | print(render_next_action(actions, tasks, namespace)) 33 | if namespace.open_urls: 34 | open_urls(actions) 35 | -------------------------------------------------------------------------------- /next_action/arguments/__init__.py: -------------------------------------------------------------------------------- 1 | """Package for parsing command line arguments.""" 2 | 3 | import argparse 4 | import os 5 | import shutil 6 | from typing import Tuple 7 | 8 | from .parser import NextActionArgumentParser 9 | 10 | 11 | def parse_arguments(version: str = "?") -> Tuple[argparse.ArgumentParser, argparse.Namespace]: 12 | """Build the argument parser and parse the command line arguments.""" 13 | # Ensure that the help info is printed using all columns available 14 | os.environ['COLUMNS'] = str(shutil.get_terminal_size().columns) 15 | parser = NextActionArgumentParser(version) 16 | return parser, parser.parse_args() 17 | -------------------------------------------------------------------------------- /next_action/arguments/config.py: -------------------------------------------------------------------------------- 1 | """Methods for reading, parsing, and validating Next-action configuration files.""" 2 | 3 | import argparse 4 | import os 5 | import string 6 | import sys 7 | from typing import Callable, Dict, List, Union 8 | 9 | from pygments.styles import get_all_styles 10 | import yaml 11 | import cerberus 12 | 13 | 14 | def read_config_file(filename: str, default_filename: str, error: Callable[[str], None]): 15 | """Read and parse the configuration file.""" 16 | try: 17 | with open(os.path.expanduser(filename), "r", encoding="utf-8") as config_file: 18 | return yaml.safe_load(config_file.read()) 19 | except FileNotFoundError as reason: 20 | if filename == default_filename: 21 | # Don't complain if there's no configuration file at the default location 22 | return {} # pragma: no cover-behave 23 | return error(f"can't open file: {reason}") 24 | except OSError as reason: 25 | return error(f"can't open file: {reason}") 26 | except yaml.YAMLError as reason: 27 | return error(f"can't parse {filename}: {reason}") 28 | 29 | 30 | def write_config_file(namespace: argparse.Namespace) -> None: 31 | """Generate a configuration file on standard out.""" 32 | intro = "# Configuration file for Next-action. Edit the settings below as you like.\n" 33 | options = dict(file=namespace.file[0] if len(namespace.file) == 1 else namespace.file, 34 | reference=namespace.reference, style=namespace.style or "default") 35 | prefixed_filters = [] 36 | for prefix, filters in (("@", namespace.contexts), ("+", namespace.projects), 37 | ("-@", namespace.excluded_contexts), ("-+", namespace.excluded_projects)): 38 | prefixed_filters.extend([prefix + filter_name for filter_name in filters]) 39 | if prefixed_filters: 40 | options["filters"] = prefixed_filters 41 | if namespace.number == sys.maxsize: 42 | options["all"] = True 43 | else: 44 | options["number"] = namespace.number 45 | if namespace.priority: 46 | options["priority"] = namespace.priority 47 | if namespace.blocked: 48 | options["blocked"] = True 49 | if namespace.groupby: 50 | options["groupby"] = namespace.groupby 51 | if namespace.line_number: 52 | options["line_number"] = True 53 | config = yaml.dump(options, default_flow_style=False) 54 | sys.stdout.write(intro + config) 55 | 56 | 57 | def validate_config_file(config, config_filename: str, error: Callable[[str], None]) -> None: 58 | """Validate the configuration file contents.""" 59 | schema = { 60 | "file": { 61 | "type": ["string", "list"], 62 | "schema": {"type": "string"} 63 | }, 64 | "number": { 65 | "type": "integer", 66 | "min": 1, 67 | "excludes": "all" 68 | }, 69 | "all": { 70 | "type": "boolean", 71 | "allowed": [True] 72 | }, 73 | "priority": { 74 | "type": "string", 75 | "allowed": list(string.ascii_uppercase) 76 | }, 77 | "filters": { 78 | "type": ["string", "list"], 79 | "regex": r"^\-?[@|\+]\S+(\s+\-?[@|\+]\S+)*", 80 | "schema": {"type": "string", "regex": r"^\-?[@|\+]\S+"} 81 | }, 82 | "line_number": { 83 | "type": "boolean", 84 | "allowed": [True] 85 | }, 86 | "reference": { 87 | "type": "string", 88 | "allowed": ["always", "never", "multiple"] 89 | }, 90 | "groupby": { 91 | "type": "string", 92 | "allowed": ["context", "duedate", "priority", "project"] 93 | }, 94 | "style": { 95 | "type": "string", 96 | "allowed": sorted(list(get_all_styles())) 97 | }, 98 | "blocked": { 99 | "type": "boolean", 100 | "allowed": [True] 101 | }, 102 | "open_urls": { 103 | "type": "boolean", 104 | "allowed": [True] 105 | } 106 | } 107 | validator = cerberus.Validator(schema) 108 | try: 109 | valid = validator.validate(config) 110 | except cerberus.validator.DocumentError as reason: 111 | error(f"{config_filename} is invalid: {reason}") 112 | if not valid: 113 | error(f"{config_filename} is invalid: {flatten_errors(validator.errors)}") 114 | 115 | 116 | def flatten_errors(error_message: Union[Dict, List, str]) -> str: 117 | """Flatten Cerberus' error messages.""" 118 | def flatten_dict(error_dict: Dict) -> str: 119 | """Return a string version of the dict.""" 120 | return ", ".join([f"{key}: {flatten_errors(value)}" for key, value in error_dict.items()]) 121 | 122 | def flatten_list(error_list: List) -> str: 123 | """Return a string version of the list.""" 124 | return ", ".join([flatten_errors(item) for item in error_list]) 125 | 126 | if isinstance(error_message, dict): 127 | return flatten_dict(error_message) 128 | if isinstance(error_message, list): 129 | return flatten_list(error_message) 130 | return error_message 131 | -------------------------------------------------------------------------------- /next_action/arguments/parser.py: -------------------------------------------------------------------------------- 1 | """Parser for the command line arguments.""" 2 | 3 | import argparse 4 | import datetime 5 | import re 6 | import shutil 7 | import string 8 | import sys 9 | import textwrap 10 | from typing import cast, List, Set, Tuple 11 | 12 | from dateutil.parser import parse 13 | from pygments.styles import get_all_styles 14 | 15 | from .config import read_config_file, write_config_file, validate_config_file 16 | 17 | 18 | ARGUMENTS = ("@", "+", "-@", "-+", "-a", "--all", "-b", "--blocked", "-c", "--config-file", "-d", "--due", 19 | "-f", "--file", "-g", "--groupby", "-h", "--help", "-n", "--number", "-o", "--overdue", 20 | "-p", "--priority", "-r", "--reference", "-s", "--style", "-u", "--open-urls", "-V", "--version") 21 | REFERENCE_CHOICES = ("always", "never", "multiple") 22 | GROUPBY_CHOICES = ("context", "duedate", "priority", "project", "source") 23 | 24 | 25 | class NextActionArgumentParser(argparse.ArgumentParser): 26 | """Command-line argument parser for Next-action.""" 27 | 28 | def __init__(self, version: str = "?") -> None: 29 | """Initialize the parser.""" 30 | super().__init__( 31 | usage=textwrap.fill("next-action [-h] [-V] [-c [] | -w] [-f ...] [-b] [-g " 32 | "[]] [-l] [-r ] [-s [