couchbase 4.2.1 → 4.2.2
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.
- package/CMakeLists.txt +1 -0
- package/deps/couchbase-cxx-client/.gitmodules +3 -0
- package/deps/couchbase-cxx-client/.idea/misc.xml +1 -0
- package/deps/couchbase-cxx-client/.idea/vcs.xml +1 -0
- package/deps/couchbase-cxx-client/CMakeLists.txt +11 -1
- package/deps/couchbase-cxx-client/README.md +3 -3
- package/deps/couchbase-cxx-client/cmake/CompilerWarnings.cmake +4 -1
- package/deps/couchbase-cxx-client/cmake/VersionInfo.cmake +13 -1
- package/deps/couchbase-cxx-client/cmake/build_version.hxx.in +1 -0
- package/deps/couchbase-cxx-client/core/cluster.hxx +15 -5
- package/deps/couchbase-cxx-client/core/impl/build_deferred_query_indexes.cxx +17 -6
- package/deps/couchbase-cxx-client/core/impl/cluster.cxx +1 -1
- package/deps/couchbase-cxx-client/core/impl/collection_query_index_manager.cxx +93 -0
- package/deps/couchbase-cxx-client/core/impl/configuration_profiles_registry.cxx +11 -0
- package/deps/couchbase-cxx-client/core/impl/create_query_index.cxx +119 -0
- package/deps/couchbase-cxx-client/core/impl/drop_query_index.cxx +108 -0
- package/deps/couchbase-cxx-client/core/impl/get.cxx +1 -1
- package/deps/couchbase-cxx-client/core/impl/get_all_query_indexes.cxx +76 -0
- package/deps/couchbase-cxx-client/core/impl/query.cxx +5 -7
- package/deps/couchbase-cxx-client/core/impl/watch_query_indexes.cxx +168 -0
- package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +15 -1
- package/deps/couchbase-cxx-client/core/logger/configuration.hxx +3 -0
- package/deps/couchbase-cxx-client/core/logger/level.hxx +21 -0
- package/deps/couchbase-cxx-client/core/logger/logger.hxx +4 -6
- package/deps/couchbase-cxx-client/core/meta/CMakeLists.txt +4 -2
- package/deps/couchbase-cxx-client/core/meta/features.hxx +31 -0
- package/deps/couchbase-cxx-client/core/meta/version.cxx +67 -5
- package/deps/couchbase-cxx-client/core/meta/version.hxx +12 -1
- package/deps/couchbase-cxx-client/core/metrics/CMakeLists.txt +4 -1
- package/deps/couchbase-cxx-client/core/metrics/logging_meter.cxx +46 -5
- package/deps/couchbase-cxx-client/core/metrics/logging_meter.hxx +10 -26
- package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -2
- package/deps/couchbase-cxx-client/core/operations/document_query.cxx +10 -12
- package/deps/couchbase-cxx-client/core/operations/document_query.hxx +1 -3
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build.cxx +8 -14
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build.hxx +2 -1
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build_deferred.hxx +15 -8
- package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +7 -14
- package/deps/couchbase-cxx-client/core/operations/management/query_index_create.hxx +2 -0
- package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +11 -16
- package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.hxx +2 -0
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.cxx +8 -12
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.hxx +4 -3
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.cxx +21 -12
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.hxx +3 -2
- package/deps/couchbase-cxx-client/core/origin.hxx +1 -1
- package/deps/couchbase-cxx-client/core/platform/uuid.cc +1 -2
- package/deps/couchbase-cxx-client/core/protocol/cmd_hello.hxx +5 -1
- package/deps/couchbase-cxx-client/core/query_context.hxx +79 -0
- package/deps/couchbase-cxx-client/core/tracing/CMakeLists.txt +3 -1
- package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.cxx +19 -4
- package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.hxx +2 -2
- package/deps/couchbase-cxx-client/core/transactions/async_attempt_context.hxx +10 -4
- package/deps/couchbase-cxx-client/core/transactions/atr_cleanup_entry.cxx +52 -63
- package/deps/couchbase-cxx-client/core/transactions/attempt_context.hxx +8 -3
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +163 -126
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.hxx +24 -37
- package/deps/couchbase-cxx-client/core/transactions/forward_compat.hxx +4 -4
- package/deps/couchbase-cxx-client/core/transactions/internal/atr_cleanup_entry.hxx +51 -13
- package/deps/couchbase-cxx-client/core/transactions/internal/client_record.hxx +26 -1
- package/deps/couchbase-cxx-client/core/transactions/internal/doc_record.hxx +21 -0
- package/deps/couchbase-cxx-client/core/transactions/internal/logging.hxx +40 -18
- package/deps/couchbase-cxx-client/core/transactions/internal/transaction_context.hxx +5 -0
- package/deps/couchbase-cxx-client/core/transactions/result.hxx +26 -0
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +48 -47
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.hxx +6 -6
- package/deps/couchbase-cxx-client/core/transactions/transaction_context.cxx +33 -19
- package/deps/couchbase-cxx-client/core/transactions/transaction_get_result.hxx +18 -2
- package/deps/couchbase-cxx-client/core/transactions/transaction_links.hxx +25 -2
- package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +4 -4
- package/deps/couchbase-cxx-client/core/transactions/transactions_cleanup.cxx +49 -56
- package/deps/couchbase-cxx-client/core/transactions/waitable_op_list.hxx +7 -7
- package/deps/couchbase-cxx-client/core/transactions.hxx +0 -12
- package/deps/couchbase-cxx-client/core/utils/binary.hxx +1 -1
- package/deps/couchbase-cxx-client/core/utils/keyspace.hxx +55 -0
- package/deps/couchbase-cxx-client/couchbase/build_query_index_options.hxx +12 -45
- package/deps/couchbase-cxx-client/couchbase/cluster.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/cluster_options.hxx +6 -7
- package/deps/couchbase-cxx-client/couchbase/collection.hxx +8 -0
- package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +218 -0
- package/deps/couchbase-cxx-client/couchbase/configuration_profiles_registry.hxx +3 -0
- package/deps/couchbase-cxx-client/couchbase/create_primary_query_index_options.hxx +166 -0
- package/deps/couchbase-cxx-client/couchbase/create_query_index_options.hxx +172 -0
- package/deps/couchbase-cxx-client/couchbase/drop_primary_query_index_options.hxx +129 -0
- package/deps/couchbase-cxx-client/couchbase/drop_query_index_options.hxx +116 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/cas.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/fmt/query_scan_consistency.hxx +46 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/query_status.hxx +70 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/tls_verify_mode.hxx +46 -0
- package/deps/couchbase-cxx-client/couchbase/get_all_query_indexes_options.hxx +100 -0
- package/deps/couchbase-cxx-client/{core → couchbase}/management/query_index.hxx +2 -2
- package/deps/couchbase-cxx-client/couchbase/metrics/meter.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/query_index_manager.hxx +178 -6
- package/deps/couchbase-cxx-client/couchbase/query_options.hxx +1 -18
- package/deps/couchbase-cxx-client/couchbase/scope.hxx +5 -2
- package/deps/couchbase-cxx-client/couchbase/tracing/request_tracer.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/transactions/async_attempt_context.hxx +11 -4
- package/deps/couchbase-cxx-client/couchbase/transactions/attempt_context.hxx +5 -3
- package/deps/couchbase-cxx-client/couchbase/transactions/transaction_keyspace.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/transactions/transaction_query_options.hxx +0 -6
- package/deps/couchbase-cxx-client/couchbase/watch_query_indexes_options.hxx +115 -0
- package/deps/couchbase-cxx-client/examples/minimal.cxx +3 -1
- package/deps/couchbase-cxx-client/test/test_integration_crud.cxx +72 -0
- package/deps/couchbase-cxx-client/test/test_integration_management.cxx +727 -310
- package/deps/couchbase-cxx-client/test/test_integration_query.cxx +4 -8
- package/deps/couchbase-cxx-client/test/test_integration_transcoders.cxx +14 -0
- package/deps/couchbase-cxx-client/test/test_transaction_transaction_public_blocking_api.cxx +34 -19
- package/deps/couchbase-cxx-client/test/test_unit_transaction_logging.cxx +66 -22
- package/deps/couchbase-cxx-client/test/test_unit_utils.cxx +51 -0
- package/deps/couchbase-cxx-client/test/tools/tool_kv_loader.cxx +2 -2
- package/deps/couchbase-cxx-client/test/utils/integration_test_guard.cxx +2 -0
- package/deps/couchbase-cxx-client/test/utils/wait_until.cxx +4 -4
- package/deps/couchbase-cxx-client/third_party/docopt/.travis.yml +103 -0
- package/deps/couchbase-cxx-client/third_party/docopt/CMakeLists.txt +129 -0
- package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-Boost-1.0 +23 -0
- package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-MIT +23 -0
- package/deps/couchbase-cxx-client/third_party/docopt/README.rst +479 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt-config.cmake +1 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.cpp +687 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.h +98 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.pc.in +9 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_private.h +676 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_util.h +122 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_value.h +341 -0
- package/deps/couchbase-cxx-client/third_party/docopt/examples/naval_fate.cpp +36 -0
- package/deps/couchbase-cxx-client/third_party/docopt/main.cpp +16 -0
- package/deps/couchbase-cxx-client/third_party/docopt/run_testcase.cpp +40 -0
- package/deps/couchbase-cxx-client/third_party/docopt/run_tests.py +72 -0
- package/deps/couchbase-cxx-client/third_party/docopt/testcases.docopt +957 -0
- package/deps/couchbase-cxx-client/tools/CMakeLists.txt +14 -0
- package/deps/couchbase-cxx-client/tools/cbc.cxx +65 -0
- package/deps/couchbase-cxx-client/tools/command.hxx +31 -0
- package/deps/couchbase-cxx-client/tools/command_registry.cxx +43 -0
- package/deps/couchbase-cxx-client/tools/command_registry.hxx +39 -0
- package/deps/couchbase-cxx-client/tools/get.cxx +267 -0
- package/deps/couchbase-cxx-client/tools/get.hxx +26 -0
- package/deps/couchbase-cxx-client/tools/query.cxx +441 -0
- package/deps/couchbase-cxx-client/tools/query.hxx +26 -0
- package/deps/couchbase-cxx-client/tools/utils.cxx +418 -0
- package/deps/couchbase-cxx-client/tools/utils.hxx +150 -0
- package/deps/couchbase-cxx-client/tools/version.cxx +82 -0
- package/deps/couchbase-cxx-client/tools/version.hxx +26 -0
- package/dist/authenticators.d.ts +2 -2
- package/dist/authenticators.js +1 -2
- package/dist/binding.d.ts +32 -16
- package/dist/cluster.js +14 -7
- package/dist/collection.d.ts +6 -0
- package/dist/collection.js +8 -0
- package/dist/queryexecutor.js +1 -1
- package/dist/queryindexmanager.d.ts +100 -4
- package/dist/queryindexmanager.js +344 -118
- package/dist/transactions.js +0 -2
- package/package.json +1 -1
- package/src/connection.cpp +2 -0
- package/src/connection.hpp +1 -0
- package/src/connection_autogen.cpp +16 -0
- package/src/jstocbpp_autogen.hpp +93 -23
- package/src/jstocbpp_basic.hpp +24 -0
- package/src/jstocbpp_transactions.hpp +0 -8
- package/tools/gen-bindings-js.js +1 -0
- package/tools/gen-bindings-json.py +4 -2
- package/deps/couchbase-cxx-client/core/transactions/logging.cxx +0 -107
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Boost Software License - Version 1.0 - August 17th, 2003
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person or organization
|
|
4
|
+
obtaining a copy of the software and accompanying documentation covered by
|
|
5
|
+
this license (the "Software") to use, reproduce, display, distribute,
|
|
6
|
+
execute, and transmit the Software, and to prepare derivative works of the
|
|
7
|
+
Software, and to permit third-parties to whom the Software is furnished to
|
|
8
|
+
do so, all subject to the following:
|
|
9
|
+
|
|
10
|
+
The copyright notices in the Software and this entire statement, including
|
|
11
|
+
the above license grant, this restriction and the following disclaimer,
|
|
12
|
+
must be included in all copies of the Software, in whole or in part, and
|
|
13
|
+
all derivative works of the Software, unless such copies or derivative
|
|
14
|
+
works are solely in the form of machine-executable object code generated by
|
|
15
|
+
a source language processor.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
20
|
+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
21
|
+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
22
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
23
|
+
DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) 2012 Vladimir Keleshev, <vladimir@keleshev.com>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software
|
|
6
|
+
without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
and/or sell copies of the Software, and to permit persons to
|
|
9
|
+
whom the Software is furnished to do so, subject to the
|
|
10
|
+
following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall
|
|
13
|
+
be included in all copies or substantial portions of the
|
|
14
|
+
Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
17
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
18
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
19
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
20
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
22
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
``docopt.cpp``: A C++11 Port
|
|
2
|
+
============================
|
|
3
|
+
|
|
4
|
+
Contents
|
|
5
|
+
--------
|
|
6
|
+
|
|
7
|
+
.. contents::
|
|
8
|
+
:local:
|
|
9
|
+
:depth: 3
|
|
10
|
+
|
|
11
|
+
docopt creates *beautiful* command-line interfaces
|
|
12
|
+
--------------------------------------------------
|
|
13
|
+
|
|
14
|
+
Isn't it awesome how ``getopt`` (and ``boost::program_options`` for you fancy
|
|
15
|
+
folk!) generate help messages based on your code?! These timeless functions
|
|
16
|
+
have been around for decades and have proven we don't need anything better, right?
|
|
17
|
+
|
|
18
|
+
*Hell no!* You know what's awesome? It's when the option parser *is*
|
|
19
|
+
generated based on the beautiful help message that you write yourself!
|
|
20
|
+
This way you don't need to write this stupid repeatable parser-code,
|
|
21
|
+
and instead can write only the help message--*the way you want it*.
|
|
22
|
+
|
|
23
|
+
**docopt** helps you create most beautiful command-line interfaces
|
|
24
|
+
*easily*:
|
|
25
|
+
|
|
26
|
+
.. code:: c++
|
|
27
|
+
|
|
28
|
+
#include "docopt.h"
|
|
29
|
+
|
|
30
|
+
#include <iostream>
|
|
31
|
+
|
|
32
|
+
static const char USAGE[] =
|
|
33
|
+
R"(Naval Fate.
|
|
34
|
+
|
|
35
|
+
Usage:
|
|
36
|
+
naval_fate ship new <name>...
|
|
37
|
+
naval_fate ship <name> move <x> <y> [--speed=<kn>]
|
|
38
|
+
naval_fate ship shoot <x> <y>
|
|
39
|
+
naval_fate mine (set|remove) <x> <y> [--moored | --drifting]
|
|
40
|
+
naval_fate (-h | --help)
|
|
41
|
+
naval_fate --version
|
|
42
|
+
|
|
43
|
+
Options:
|
|
44
|
+
-h --help Show this screen.
|
|
45
|
+
--version Show version.
|
|
46
|
+
--speed=<kn> Speed in knots [default: 10].
|
|
47
|
+
--moored Moored (anchored) mine.
|
|
48
|
+
--drifting Drifting mine.
|
|
49
|
+
)";
|
|
50
|
+
|
|
51
|
+
int main(int argc, const char** argv)
|
|
52
|
+
{
|
|
53
|
+
std::map<std::string, docopt::value> args
|
|
54
|
+
= docopt::docopt(USAGE,
|
|
55
|
+
{ argv + 1, argv + argc },
|
|
56
|
+
true, // show help if requested
|
|
57
|
+
"Naval Fate 2.0"); // version string
|
|
58
|
+
|
|
59
|
+
for(auto const& arg : args) {
|
|
60
|
+
std::cout << arg.first << arg.second << std::endl;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Beat that! The option parser is generated based on the docstring above
|
|
67
|
+
that is passed to ``docopt::docopt`` function. ``docopt`` parses the usage
|
|
68
|
+
pattern (``"Usage: ..."``) and option descriptions (lines starting
|
|
69
|
+
with a dash "``-``") and ensures that the program invocation matches the
|
|
70
|
+
usage pattern; it parses options, arguments and commands based on
|
|
71
|
+
that. The basic idea is that *a good help message has all necessary
|
|
72
|
+
information in it to make a parser*.
|
|
73
|
+
|
|
74
|
+
Getting and using
|
|
75
|
+
-----------------
|
|
76
|
+
|
|
77
|
+
To get *docopt.cpp*, the simplest is to use `Conda <https://github.com/conda-forge/docopt.cpp-feedstock>`_::
|
|
78
|
+
|
|
79
|
+
conda install -c conda-forge docopt.cpp
|
|
80
|
+
|
|
81
|
+
Alternatively manual installation is done using (unix)::
|
|
82
|
+
|
|
83
|
+
git clone
|
|
84
|
+
cmake .
|
|
85
|
+
make install
|
|
86
|
+
|
|
87
|
+
To link *docopt.cpp*, the simplest is to use CMake. The general structure of your
|
|
88
|
+
``CMakeLists.txt`` would be as follows::
|
|
89
|
+
|
|
90
|
+
cmake_minimum_required(VERSION 3.1)
|
|
91
|
+
|
|
92
|
+
project(example)
|
|
93
|
+
|
|
94
|
+
find_package(docopt COMPONENTS CXX REQUIRED)
|
|
95
|
+
include_directories(${DOCOPT_INCLUDE_DIRS})
|
|
96
|
+
|
|
97
|
+
add_executable(${PROJECT_NAME} ...)
|
|
98
|
+
|
|
99
|
+
target_link_libraries(${PROJECT_NAME} docopt)
|
|
100
|
+
|
|
101
|
+
C++11 port details
|
|
102
|
+
------------------
|
|
103
|
+
|
|
104
|
+
This is a port of the ``docopt.py`` module (https://github.com/docopt/docopt),
|
|
105
|
+
and we have tried to maintain full feature parity (and code structure) as the
|
|
106
|
+
original.
|
|
107
|
+
|
|
108
|
+
This port is written in C++11 and also requires a good C++11 standard library
|
|
109
|
+
(in particular, one with ``regex`` support). The following compilers are known
|
|
110
|
+
to work with docopt:
|
|
111
|
+
|
|
112
|
+
- Clang 3.3 and later
|
|
113
|
+
- GCC 4.9
|
|
114
|
+
- Visual C++ 2015 RC
|
|
115
|
+
|
|
116
|
+
GCC-4.8 can work, but the std::regex module needs to be replaced with ``Boost.Regex``.
|
|
117
|
+
In that case, you will need to define ``DOCTOPT_USE_BOOST_REGEX`` when compiling
|
|
118
|
+
docopt, and link your code with the appropriated Boost libraries. A relatively
|
|
119
|
+
recent version of Boost is needed: 1.55 works, but 1.46 does not for example.
|
|
120
|
+
|
|
121
|
+
This port is licensed under the MIT license, just like the original module.
|
|
122
|
+
However, we are also dual-licensing this code under the Boost License, version 1.0,
|
|
123
|
+
as this is a popular C++ license. The licenses are similar and you are free to
|
|
124
|
+
use this code under the terms of either license.
|
|
125
|
+
|
|
126
|
+
The differences from the Python port are:
|
|
127
|
+
|
|
128
|
+
* the addition of a ``docopt_parse`` function, which does not terminate
|
|
129
|
+
the program on error
|
|
130
|
+
* a ``docopt::value`` type to hold the various value types that can be parsed.
|
|
131
|
+
We considered using boost::variant, but it seems better to have no external
|
|
132
|
+
dependencies (beyond a good STL).
|
|
133
|
+
* because C++ is statically-typed and Python is not, we had to make some
|
|
134
|
+
changes to the interfaces of the internal parse tree types.
|
|
135
|
+
* because ``std::regex`` does not have an equivalent to Python's regex.split,
|
|
136
|
+
some of the regex's had to be restructured and additional loops used.
|
|
137
|
+
|
|
138
|
+
API
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
.. code:: c++
|
|
142
|
+
|
|
143
|
+
docopt::docopt(doc, argv, help /* =true */, version /* ="" */, options_first /* =false */)
|
|
144
|
+
|
|
145
|
+
``docopt`` takes 2 required and 3 optional arguments:
|
|
146
|
+
|
|
147
|
+
- ``doc`` is a string that contains a **help message** that will be parsed to
|
|
148
|
+
create the option parser. The simple rules of how to write such a
|
|
149
|
+
help message are given in next sections. Here is a quick example of
|
|
150
|
+
such a string (note that this example uses the "raw string literal" feature
|
|
151
|
+
that was added to C++11):
|
|
152
|
+
|
|
153
|
+
.. code:: c++
|
|
154
|
+
|
|
155
|
+
R"(Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]
|
|
156
|
+
|
|
157
|
+
-h --help show this
|
|
158
|
+
-s --sorted sorted output
|
|
159
|
+
-o FILE specify output file [default: ./test.txt]
|
|
160
|
+
--quiet print less text
|
|
161
|
+
--verbose print more text
|
|
162
|
+
)"
|
|
163
|
+
|
|
164
|
+
- ``argv`` is a vector of strings representing the args passed. Although
|
|
165
|
+
main usually takes a ``(int argc, const char** argv)`` pair, you can
|
|
166
|
+
pass the value ``{argv+1, argv+argc}`` to generate the vector automatically.
|
|
167
|
+
(Note we skip the argv[0] argument!) Alternatively you can supply a list of
|
|
168
|
+
strings like ``{ "--verbose", "-o", "hai.txt" }``.
|
|
169
|
+
|
|
170
|
+
- ``help``, by default ``true``, specifies whether the parser should
|
|
171
|
+
automatically print the help message (supplied as ``doc``) and
|
|
172
|
+
terminate, in case ``-h`` or ``--help`` option is encountered
|
|
173
|
+
(options should exist in usage pattern, more on that below). If you
|
|
174
|
+
want to handle ``-h`` or ``--help`` options manually (as other
|
|
175
|
+
options), set ``help=false``.
|
|
176
|
+
|
|
177
|
+
- ``version``, by default empty, is an optional argument that
|
|
178
|
+
specifies the version of your program. If supplied, then, (assuming
|
|
179
|
+
``--version`` option is mentioned in usage pattern) when parser
|
|
180
|
+
encounters the ``--version`` option, it will print the supplied
|
|
181
|
+
version and terminate. ``version`` could be any printable object,
|
|
182
|
+
but most likely a string, e.g. ``"2.1.0rc1"``.
|
|
183
|
+
|
|
184
|
+
Note, when ``docopt`` is set to automatically handle ``-h``,
|
|
185
|
+
``--help`` and ``--version`` options, you still need to mention
|
|
186
|
+
them in usage pattern for this to work (also so your users to
|
|
187
|
+
know about them!)
|
|
188
|
+
|
|
189
|
+
- ``options_first``, by default ``false``. If set to ``true`` will
|
|
190
|
+
disallow mixing options and positional argument. I.e. after first
|
|
191
|
+
positional argument, all arguments will be interpreted as positional
|
|
192
|
+
even if the look like options. This can be used for strict
|
|
193
|
+
compatibility with POSIX, or if you want to dispatch your arguments
|
|
194
|
+
to other programs.
|
|
195
|
+
|
|
196
|
+
The **return** value is a ``map<string, docopt::value>`` with options,
|
|
197
|
+
arguments and commands as keys, spelled exactly like in your help message.
|
|
198
|
+
Long versions of options are given priority. For example, if you invoke the
|
|
199
|
+
top example as::
|
|
200
|
+
|
|
201
|
+
naval_fate ship Guardian move 100 150 --speed=15
|
|
202
|
+
|
|
203
|
+
the return dictionary will be:
|
|
204
|
+
|
|
205
|
+
.. code:: python
|
|
206
|
+
|
|
207
|
+
{"--drifting": false, "mine": false,
|
|
208
|
+
"--help": false, "move": true,
|
|
209
|
+
"--moored": false, "new": false,
|
|
210
|
+
"--speed": "15", "remove": false,
|
|
211
|
+
"--version": false, "set": false,
|
|
212
|
+
"<name>": ["Guardian"], "ship": true,
|
|
213
|
+
"<x>": "100", "shoot": false,
|
|
214
|
+
"<y>": "150"}
|
|
215
|
+
|
|
216
|
+
If any parsing error (in either the usage, or due to incorrect user inputs) is
|
|
217
|
+
encountered, the program will exit with exit code -1.
|
|
218
|
+
|
|
219
|
+
Note that there is another function that does not exit on error, and instead will
|
|
220
|
+
propagate an exception that you can catch and process as you like. See the docopt.h file
|
|
221
|
+
for information on the exceptions and usage:
|
|
222
|
+
|
|
223
|
+
.. code:: c++
|
|
224
|
+
|
|
225
|
+
docopt::docopt_parse(doc, argv, help /* =true */, version /* =true */, options_first /* =false)
|
|
226
|
+
|
|
227
|
+
Help message format
|
|
228
|
+
-------------------
|
|
229
|
+
|
|
230
|
+
Help message consists of 2 parts:
|
|
231
|
+
|
|
232
|
+
- Usage pattern, e.g.::
|
|
233
|
+
|
|
234
|
+
Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]
|
|
235
|
+
|
|
236
|
+
- Option descriptions, e.g.::
|
|
237
|
+
|
|
238
|
+
-h --help show this
|
|
239
|
+
-s --sorted sorted output
|
|
240
|
+
-o FILE specify output file [default: ./test.txt]
|
|
241
|
+
--quiet print less text
|
|
242
|
+
--verbose print more text
|
|
243
|
+
|
|
244
|
+
Their format is described below; other text is ignored.
|
|
245
|
+
|
|
246
|
+
Usage pattern format
|
|
247
|
+
--------------------
|
|
248
|
+
|
|
249
|
+
**Usage pattern** is a substring of ``doc`` that starts with
|
|
250
|
+
``usage:`` (case *insensitive*) and ends with a *visibly* empty line.
|
|
251
|
+
Minimum example:
|
|
252
|
+
|
|
253
|
+
.. code:: python
|
|
254
|
+
|
|
255
|
+
"""Usage: my_program
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
The first word after ``usage:`` is interpreted as your program's name.
|
|
260
|
+
You can specify your program's name several times to signify several
|
|
261
|
+
exclusive patterns:
|
|
262
|
+
|
|
263
|
+
.. code:: python
|
|
264
|
+
|
|
265
|
+
"""Usage: my_program FILE
|
|
266
|
+
my_program COUNT FILE
|
|
267
|
+
|
|
268
|
+
"""
|
|
269
|
+
|
|
270
|
+
Each pattern can consist of the following elements:
|
|
271
|
+
|
|
272
|
+
- **<arguments>**, **ARGUMENTS**. Arguments are specified as either
|
|
273
|
+
upper-case words, e.g. ``my_program CONTENT-PATH`` or words
|
|
274
|
+
surrounded by angular brackets: ``my_program <content-path>``.
|
|
275
|
+
- **--options**. Options are words started with dash (``-``), e.g.
|
|
276
|
+
``--output``, ``-o``. You can "stack" several of one-letter
|
|
277
|
+
options, e.g. ``-oiv`` which will be the same as ``-o -i -v``. The
|
|
278
|
+
options can have arguments, e.g. ``--input=FILE`` or ``-i FILE`` or
|
|
279
|
+
even ``-iFILE``. However it is important that you specify option
|
|
280
|
+
descriptions if you want your option to have an argument, a default
|
|
281
|
+
value, or specify synonymous short/long versions of the option (see
|
|
282
|
+
next section on option descriptions).
|
|
283
|
+
- **commands** are words that do *not* follow the described above
|
|
284
|
+
conventions of ``--options`` or ``<arguments>`` or ``ARGUMENTS``,
|
|
285
|
+
plus two special commands: dash "``-``" and double dash "``--``"
|
|
286
|
+
(see below).
|
|
287
|
+
|
|
288
|
+
Use the following constructs to specify patterns:
|
|
289
|
+
|
|
290
|
+
- **[ ]** (brackets) **optional** elements. e.g.: ``my_program
|
|
291
|
+
[-hvqo FILE]``
|
|
292
|
+
- **( )** (parens) **required** elements. All elements that are *not*
|
|
293
|
+
put in **[ ]** are also required, e.g.: ``my_program
|
|
294
|
+
--path=<path> <file>...`` is the same as ``my_program
|
|
295
|
+
(--path=<path> <file>...)``. (Note, "required options" might be not
|
|
296
|
+
a good idea for your users).
|
|
297
|
+
- **|** (pipe) **mutually exclusive** elements. Group them using **(
|
|
298
|
+
)** if one of the mutually exclusive elements is required:
|
|
299
|
+
``my_program (--clockwise | --counter-clockwise) TIME``. Group
|
|
300
|
+
them using **[ ]** if none of the mutually exclusive elements are
|
|
301
|
+
required: ``my_program [--left | --right]``.
|
|
302
|
+
- **...** (ellipsis) **one or more** elements. To specify that
|
|
303
|
+
arbitrary number of repeating elements could be accepted, use
|
|
304
|
+
ellipsis (``...``), e.g. ``my_program FILE ...`` means one or
|
|
305
|
+
more ``FILE``-s are accepted. If you want to accept zero or more
|
|
306
|
+
elements, use brackets, e.g.: ``my_program [FILE ...]``. Ellipsis
|
|
307
|
+
works as a unary operator on the expression to the left.
|
|
308
|
+
- **[options]** (case sensitive) shortcut for any options. You can
|
|
309
|
+
use it if you want to specify that the usage pattern could be
|
|
310
|
+
provided with any options defined below in the option-descriptions
|
|
311
|
+
and do not want to enumerate them all in usage-pattern.
|
|
312
|
+
- "``[--]``". Double dash "``--``" is used by convention to separate
|
|
313
|
+
positional arguments that can be mistaken for options. In order to
|
|
314
|
+
support this convention add "``[--]``" to your usage patterns.
|
|
315
|
+
- "``[-]``". Single dash "``-``" is used by convention to signify that
|
|
316
|
+
``stdin`` is used instead of a file. To support this add "``[-]``"
|
|
317
|
+
to your usage patterns. "``-``" acts as a normal command.
|
|
318
|
+
|
|
319
|
+
If your pattern allows to match argument-less option (a flag) several
|
|
320
|
+
times::
|
|
321
|
+
|
|
322
|
+
Usage: my_program [-v | -vv | -vvv]
|
|
323
|
+
|
|
324
|
+
then number of occurrences of the option will be counted. I.e.
|
|
325
|
+
``args['-v']`` will be ``2`` if program was invoked as ``my_program
|
|
326
|
+
-vv``. Same works for commands.
|
|
327
|
+
|
|
328
|
+
If your usage pattern allows to match same-named option with argument
|
|
329
|
+
or positional argument several times, the matched arguments will be
|
|
330
|
+
collected into a list::
|
|
331
|
+
|
|
332
|
+
Usage: my_program <file> <file> --path=<path>...
|
|
333
|
+
|
|
334
|
+
I.e. invoked with ``my_program file1 file2 --path=./here
|
|
335
|
+
--path=./there`` the returned dict will contain ``args['<file>'] ==
|
|
336
|
+
['file1', 'file2']`` and ``args['--path'] == ['./here', './there']``.
|
|
337
|
+
|
|
338
|
+
Option descriptions format
|
|
339
|
+
--------------------------
|
|
340
|
+
|
|
341
|
+
**Option descriptions** consist of a list of options that you put
|
|
342
|
+
below your usage patterns.
|
|
343
|
+
|
|
344
|
+
It is necessary to list option descriptions in order to specify:
|
|
345
|
+
|
|
346
|
+
- synonymous short and long options,
|
|
347
|
+
- if an option has an argument,
|
|
348
|
+
- if option's argument has a default value.
|
|
349
|
+
|
|
350
|
+
The rules are as follows:
|
|
351
|
+
|
|
352
|
+
- Every line in ``doc`` that starts with ``-`` or ``--`` (not counting
|
|
353
|
+
spaces) is treated as an option description, e.g.::
|
|
354
|
+
|
|
355
|
+
Options:
|
|
356
|
+
--verbose # GOOD
|
|
357
|
+
-o FILE # GOOD
|
|
358
|
+
Other: --bad # BAD, line does not start with dash "-"
|
|
359
|
+
|
|
360
|
+
- To specify that option has an argument, put a word describing that
|
|
361
|
+
argument after space (or equals "``=``" sign) as shown below. Follow
|
|
362
|
+
either <angular-brackets> or UPPER-CASE convention for options'
|
|
363
|
+
arguments. You can use comma if you want to separate options. In
|
|
364
|
+
the example below, both lines are valid. However you are recommended
|
|
365
|
+
to stick to a single style.::
|
|
366
|
+
|
|
367
|
+
-o FILE --output=FILE # without comma, with "=" sign
|
|
368
|
+
-i <file>, --input <file> # with comma, without "=" sing
|
|
369
|
+
|
|
370
|
+
- Use two spaces to separate options with their informal description::
|
|
371
|
+
|
|
372
|
+
--verbose More text. # BAD, will be treated as if verbose option had
|
|
373
|
+
# an argument "More", so use 2 spaces instead
|
|
374
|
+
-q Quit. # GOOD
|
|
375
|
+
-o FILE Output file. # GOOD
|
|
376
|
+
--stdout Use stdout. # GOOD, 2 spaces
|
|
377
|
+
|
|
378
|
+
- If you want to set a default value for an option with an argument,
|
|
379
|
+
put it into the option-description, in form ``[default:
|
|
380
|
+
<my-default-value>]``::
|
|
381
|
+
|
|
382
|
+
--coefficient=K The K coefficient [default: 2.95]
|
|
383
|
+
--output=FILE Output file [default: test.txt]
|
|
384
|
+
--directory=DIR Some directory [default: ./]
|
|
385
|
+
|
|
386
|
+
- If the option is not repeatable, the value inside ``[default: ...]``
|
|
387
|
+
will be interpreted as string. If it *is* repeatable, it will be
|
|
388
|
+
split into a list on whitespace::
|
|
389
|
+
|
|
390
|
+
Usage: my_program [--repeatable=<arg> --repeatable=<arg>]
|
|
391
|
+
[--another-repeatable=<arg>]...
|
|
392
|
+
[--not-repeatable=<arg>]
|
|
393
|
+
|
|
394
|
+
# will be ['./here', './there']
|
|
395
|
+
--repeatable=<arg> [default: ./here ./there]
|
|
396
|
+
|
|
397
|
+
# will be ['./here']
|
|
398
|
+
--another-repeatable=<arg> [default: ./here]
|
|
399
|
+
|
|
400
|
+
# will be './here ./there', because it is not repeatable
|
|
401
|
+
--not-repeatable=<arg> [default: ./here ./there]
|
|
402
|
+
|
|
403
|
+
Examples
|
|
404
|
+
--------
|
|
405
|
+
|
|
406
|
+
We have an extensive list of `examples
|
|
407
|
+
<https://github.com/docopt/docopt/tree/master/examples>`_ which cover
|
|
408
|
+
every aspect of functionality of **docopt**. Try them out, read the
|
|
409
|
+
source if in doubt.
|
|
410
|
+
|
|
411
|
+
There are also very interesting applications and ideas at that page.
|
|
412
|
+
Check out the sister project for more information!
|
|
413
|
+
|
|
414
|
+
Subparsers, multi-level help and *huge* applications (like git)
|
|
415
|
+
---------------------------------------------------------------
|
|
416
|
+
|
|
417
|
+
If you want to split your usage-pattern into several, implement
|
|
418
|
+
multi-level help (with separate help-screen for each subcommand),
|
|
419
|
+
want to interface with existing scripts that don't use **docopt**, or
|
|
420
|
+
you're building the next "git", you will need the new ``options_first``
|
|
421
|
+
parameter (described in API section above). To get you started quickly
|
|
422
|
+
we implemented a subset of git command-line interface as an example:
|
|
423
|
+
`examples/git
|
|
424
|
+
<https://github.com/docopt/docopt/tree/master/examples/git>`_
|
|
425
|
+
|
|
426
|
+
Compiling the example / Running the tests
|
|
427
|
+
-----------------------------------------
|
|
428
|
+
|
|
429
|
+
The original Python module includes some language-agnostic unit tests,
|
|
430
|
+
and these can be run with this port as well.
|
|
431
|
+
|
|
432
|
+
The tests are a Python driver that uses the testcases.docopt file to then invoke
|
|
433
|
+
a C++ test case runner (run_testcase.cpp)::
|
|
434
|
+
|
|
435
|
+
$ clang++ --std=c++11 --stdlib=libc++ docopt.cpp run_testcase.cpp -o run_testcase
|
|
436
|
+
$ python run_tests.py
|
|
437
|
+
PASS (175)
|
|
438
|
+
|
|
439
|
+
You can also compile the example shown at the start (included as example.cpp)::
|
|
440
|
+
|
|
441
|
+
$ clang++ --std=c++11 --stdlib=libc++ -I . docopt.cpp examples/naval_fate.cpp -o naval_fate
|
|
442
|
+
$ ./naval_fate --help
|
|
443
|
+
[ ... ]
|
|
444
|
+
$ ./naval_fate ship Guardian move 100 150 --speed=15
|
|
445
|
+
--drifting: false
|
|
446
|
+
--help: false
|
|
447
|
+
--moored: false
|
|
448
|
+
--speed: "15"
|
|
449
|
+
--version: false
|
|
450
|
+
<name>: ["Guardian"]
|
|
451
|
+
<x>: "100"
|
|
452
|
+
<y>: "150"
|
|
453
|
+
mine: false
|
|
454
|
+
move: true
|
|
455
|
+
new: false
|
|
456
|
+
remove: false
|
|
457
|
+
set: false
|
|
458
|
+
ship: true
|
|
459
|
+
shoot: false
|
|
460
|
+
|
|
461
|
+
Development
|
|
462
|
+
-----------
|
|
463
|
+
|
|
464
|
+
Comments and suggestions are *very* welcome! If you find issues, please
|
|
465
|
+
file them and help improve our code!
|
|
466
|
+
|
|
467
|
+
Please note, however, that we have tried to stay true to the original
|
|
468
|
+
Python code. If you have any major patches, structural changes, or new features,
|
|
469
|
+
we might want to first negotiate these changes into the Python code first.
|
|
470
|
+
However, bring it up! Let's hear it!
|
|
471
|
+
|
|
472
|
+
Changelog
|
|
473
|
+
---------
|
|
474
|
+
|
|
475
|
+
**docopt** follows `semantic versioning <http://semver.org>`_. The
|
|
476
|
+
first release with stable API will be 1.0.0 (soon).
|
|
477
|
+
|
|
478
|
+
- 0.6.2 Bugfix release (still based on docopt 0.6.1)
|
|
479
|
+
- 0.6.1 The initial C++ port of docopt.py (based on docopt 0.6.1)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include("${CMAKE_CURRENT_LIST_DIR}/docopt-targets.cmake")
|