8000 Merge pull request #718 from andreasfertig/fixIssue515 · andreasfertig/cppinsights@da1e5ec · GitHub
[go: up one dir, main page]

Skip to content

Commit da1e5ec

Browse files
Merge pull request #718 from andreasfertig/fixIssue515
Fixed #515: Added bash autocomplete script.
2 parents bbaff70 + 0c0a05d commit da1e5ec

40 files changed

+470
-122
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ jobs:
549549
550550
- name: Run tests
551551
if: matrix.config.run_tests == 'Yes'
552+
shell: bash
552553
id: run_tests
553554
run: |
554555
cmake --build build --target tests

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ else()
656656
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:insights> --cxx ${CMAKE_CXX_COMPILER} ${TEST_FAILURE_IS_OK} ${TEST_USE_LIBCPP} ${LLVM_PROF_DIR}
657657
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/testSTDIN.sh ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:insights>
658658
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/testInvalidOption.sh ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:insights>
659-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:insights> ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py
659+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell/test-bash-completion.sh ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bash-autocomplete.sh ${TEST_FAILURE_IS_OK}
660+
DEPENDS ${CM DD41 AKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:insights> ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell/test-bash-completion.sh
660661
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests
661662
COMMENT "Running tests" VERBATIM
662663
)
@@ -667,7 +668,8 @@ if (NOT WIN32)
667668
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py --insights ${CMAKE_CURRENT_BINARY_DIR}/insights --cxx ${CMAKE_CXX_COMPILER} --update-tests ${TEST_FAILURE_IS_OK}
668669
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/testSTDIN.sh ${CMAKE_CURRENT_BINARY_DIR}/insights
669670
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/testInvalidOption.sh ${CMAKE_CURRENT_BINARY_DIR}/insights
670-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/insights ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py
671+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell/test-bash-completion.sh ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell ${CMAKE_CURRENT_SOURCE_DIR}/scripts/bash-autocomplete.sh
672+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/insights ${CMAKE_CURRENT_SOURCE_DIR}/tests/runTest.py ${CMAKE_CURRENT_SOURCE_DIR}/tests/shell/test-bash-completion.sh
671673
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests
672674
COMMENT "Running tests" VERBATIM
673675
)

Insights.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ static llvm::cl::OptionCategory gInsightEduCategory(
5555
"This transformations are only for education purposes. The resulting code most likely does not compile."sv);
5656
//-----------------------------------------------------------------------------
5757

58-
static llvm::cl::opt<bool> gStdinMode("stdin",
59-
llvm::cl::desc("Read the input from <stdin>."sv),
60-
llvm::cl::init(false),
61-
llvm::cl::cat(gInsightCategory));
62-
//-----------------------------------------------------------------------------
63-
64-
static llvm::cl::opt<bool>
65-
gUseLibCpp("use-libc++", llvm::cl::desc("Use libc++."sv), llvm::cl::init(false), llvm::cl::cat(gInsightCategory));
66-
//-----------------------------------------------------------------------------
67-
6858
#define INSIGHTS_OPT(option, name, deflt, description, category) \
6959
static llvm::cl::opt<bool, true> g##name(option, \
7060
llvm::cl::desc(std::string_view{description}), \
@@ -397,7 +387,17 @@ extern struct __mptr* __vtbl_array[];
397387
auto opExpected = CommonOptionsParser::create(argc, argv, gInsightCategory);
398388

399389
if(auto err = opExpected.takeError()) {
400-
llvm::errs() << toString(std::move(err)) << "\n";
390+
if(gAutoComplete) {
391+
#define INSIGHTS_OPT(option, name, deflt, description, category) llvm::outs() << "--" << option << " ";
392+
393+
#include "InsightsOptions.def"
394+
395+
return 0;
396+
} else {
397+
398+
llvm::errs() << toString(std::move(err)) << "\n";
399+
}
400+
401401
return 1;
402402
}
403403

InsightsOptions.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ INSIGHTS_OPT("edu-show-coroutine-transformation",
3131
gInsightEduCategory)
3232
INSIGHTS_OPT("edu-show-cfront", UseShow2C, false, "Show transformation to C", gInsightEduCategory)
3333
INSIGHTS_OPT("edu-show-lifetime", ShowLifetime, false, "Show lifetime of objects", gInsightEduCategory)
34+
35+
INSIGHTS_OPT("stdin", StdinMode, false, "Read the input from <stdin>.", gInsightCategory)
36+
INSIGHTS_OPT("use-libc++", UseLibCpp, false, "Use libc++ (LLVM) instead of libstdc++ (GNU).", gInsightCategory)
37+
INSIGHTS_OPT("autocomplete", AutoComplete, false, "Generate list of options for autocomplete and exit.", gInsightCategory)
38+
3439
#undef INSIGHTS_OPT

Readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ At least for macOS, you can install C++ Insights via Homebrew thanks to [this fo
263263
brew install cppinsights
264264
```
265265
266+
## Bash autocomplete
267+
268+
There is a bash autocomplete script. It autocompletes the C++ Insights options as well as the Clang options provided after `--`.
269+
You can download it with the following commands:
270+
271+
```
272+
cd <YOUR_BASH_COMPLETION.D>
273+
curl -o insights https://github.com/andreasfertig/cppinsights/tree/main/scripts/bash-autocomplete.sh
274+
```
275+
266276
267277
## Compatibility
268278

docs/CommandLineOptions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [alt-syntax-for](@ref alt_syntax_for)
44
* [alt-syntax-subscription](@ref alt_syntax_subscription)
5+
* [autocomplete](@ref autocomplete)
56
* [edu-show-cfront](@ref edu_show_cfront)
67
* [edu-show-coroutine-transformation](@ref edu_show_coroutine_transformation)
78
* [edu-show-initlist](@ref edu_show_initlist)
@@ -10,3 +11,5 @@
1011
* [edu-show-padding](@ref edu_show_padding)
1112
* [show-all-callexpr-template-parameters](@ref show_all_callexpr_template_parameters)
1213
* [show-all-implicit-casts](@ref show_all_implicit_casts)
14+
* [stdin](@ref stdin)
15+
* [use-libc++](@ref use_libc++)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Just prints out all the C++ Insights options.

docs/cmdl-examples/edu-show-cfront.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// cmdlineinsights:-edu-show-cfront
2-
31
#include <cstdio>
42

53
class A

docs/cmdl-examples/edu-show-coroutine-transformation.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
#if __has_include(<coroutine>)
21
#include <coroutine>
3-
#elif __has_include(<experimental/coroutine>)
4-
#include <experimental/coroutine>
5-
6-
namespace std {
7-
using namespace std::experimental;
8-
}
9-
#else
10-
#error "No coroutine header"
11-
#endif
12-
132
#include <cstdio>
143
#include <exception>
154
#include <new>
5+
#include <utility>
166

177
struct generator
188
{
@@ -35,7 +25,7 @@ struct generator
3525

3626
generator(generator const&) = delete;
3727
generator(generator&& rhs)
38-
: p{std::exchange(rhs.p, nullptr)}
28+
: handle{std::exchange(rhs.handle, nullptr)}
3929
{
4030
}
4131

docs/cmdl-examples/stdin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main()
2+
{
3+
// Nothing going on here.
4+
}

0 commit comments

Comments
 (0)
0