Skip to content

Commit d4040fb

Browse files
authored
Add init-library and combine init and hello into init-hello (#7)
1 parent ccc7098 commit d4040fb

File tree

5 files changed

+90
-47
lines changed

5 files changed

+90
-47
lines changed

.cppsm/travis-ci

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@ export PATH="$PWD/bin:$PATH"
55
# shellcheck source=../commands/.settings
66
. commands/.settings
77

8-
mkdir self-test && cd "$_"
9-
10-
git init
11-
cppsm init
12-
cppsm hello
8+
# git config
139

10+
git config --global core.autocrlf false
1411
git config --global user.email "[email protected]"
1512
git config --global user.name "CI script"
13+
14+
# init-library
15+
16+
mkdir library && cd "$_"
17+
18+
git init
19+
cppsm init-library
20+
CXX='' CC='' cppsm test
21+
22+
cd ..
23+
24+
# self test
25+
26+
mkdir hello && cd "$_"
27+
28+
git init
29+
cppsm init-hello
30+
1631
git commit -m Initial
1732

1833
../travis-ci

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ __cppsm_complete() {
1818
case "$PREVIOUS" in
1919
cppsm)
2020
# shellcheck disable=SC2207
21-
COMPREPLY=($(compgen -W "add build build-watch clone format hello init list remove setup test test-watch update upgrade" -- "$CURRENT"))
21+
COMPREPLY=($(compgen -W "add build build-watch clone format init init-hello init-library list remove setup test test-watch update upgrade" -- "$CURRENT"))
2222
;;
2323
add)
2424
# shellcheck disable=SC2207

commands/init

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
# shellcheck source=.settings
44
. "${BASH_SOURCE%/*}/.settings"
55

6-
if [ "$#" -ne 0 ] || [ ! -d .git ]; then
6+
if [ -z "$NAME" ]; then
7+
export NAME="${PWD##*/}"
8+
fi
9+
export VERSION="${VERSION:-v1}"
10+
11+
if [ "$#" -ne 0 ] || [ ! -d .git ] || \
12+
[ "$NAME" != "$(echo "$NAME" | grep -o '^[a-zA-Z0-9_]\+')" ] ; then
713
CMD="${0##*/}"
814
cat << EOF
915
Usage: $CMD
1016
17+
Options:
18+
19+
NAME=$NAME|...
20+
VERSION=$VERSION|...
21+
1122
Initializes a new C++ project with cppsm configuration files or updates an
1223
existing project to use the latest configuration files. Run $CMD in the
1324
top-level directory of a fresh git project.
@@ -36,19 +47,24 @@ ln -fs .cppsm/.clang-format .clang-format
3647
ln -fs .cppsm/.gitignore .gitignore
3748
ln -fs .cppsm/.prettierrc .prettierrc
3849

39-
if [ ! -e CMakeLists.txt ]; then
40-
cat << EOF > CMakeLists.txt
50+
add-file() {
51+
if [[ "$1" =~ / ]]; then mkdir -p "${1%/*}"; fi
52+
if [ ! -e "$1" ]; then
53+
cat > "$1"
54+
git add "$1"
55+
fi
56+
}
57+
58+
add-file CMakeLists.txt << EOF
4159
cmake_minimum_required(VERSION 3.10)
42-
project(${PWD##*/})
60+
project($NAME)
4361
include(.cppsm/c++17.cmake)
4462
EOF
45-
fi
4663

4764
cp "$CPPSM/.travis.yml" .travis.yml
4865

4966
git add \
5067
.clang-format \
5168
.gitignore \
5269
.prettierrc \
53-
.travis.yml \
54-
CMakeLists.txt
70+
.travis.yml
Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
#!/bin/bash -e
22

3-
# shellcheck source=.settings
4-
. "${BASH_SOURCE%/*}/.settings"
5-
6-
if [ "$#" -ne 0 ] || \
7-
[ ! -f CMakeLists.txt ] || \
8-
[ -e equipment ] || \
9-
[ -e internals ] || \
10-
[ -e provides ] || \
11-
[ -e requires ] ; then
12-
CMD="${0##*/}"
13-
cat << EOF
14-
Usage: $CMD
15-
16-
Creates an example "Hello, world!" program in a freshly initialized project
17-
directory.
18-
EOF
19-
exit 1
20-
fi
21-
22-
mkdir -p provides/include/message_v1
3+
# shellcheck source=init
4+
. "${BASH_SOURCE%/*}/init"
235

24-
cat << EOF > provides/include/message_v1/hello.hpp
6+
add-file provides/include/message_v1/hello.hpp << EOF
257
#include <string>
268
279
namespace message_v1 {
@@ -31,25 +13,21 @@ std::string hello(const std::string &to);
3113
}
3214
EOF
3315

34-
mkdir -p provides/library
35-
36-
cat << EOF > provides/library/hello.cpp
16+
add-file provides/library/hello.cpp << EOF
3717
#include "message_v1/hello.hpp"
3818
3919
std::string message_v1::hello(const std::string &to) {
4020
return "Hello, " + to + "!";
4121
}
4222
EOF
4323

44-
cat << EOF > provides/CMakeLists.txt
24+
add-file provides/CMakeLists.txt << EOF
4525
add_conventional_library(message_v1)
4626
EOF
4727

4828
"$CPPSM/commands/add" equipment https://github.com/per-framework/testing.cpp.git v1
4929

50-
mkdir -p internals/testing
51-
52-
cat << EOF > internals/testing/message_test.cpp
30+
add-file internals/testing/message_test.cpp << EOF
5331
#include "message_v1/hello.hpp"
5432
5533
#include "testing_v1/test.hpp"
@@ -60,9 +38,7 @@ auto hello_test =
6038
test([]() { verify("Hello, there!" == message_v1::hello("there")); });
6139
EOF
6240

63-
mkdir -p internals/program
64-
65-
cat << EOF > internals/program/hello.cpp
41+
add-file internals/program/hello.cpp << EOF
6642
#include "message_v1/hello.hpp"
6743
6844
#include <iostream>
@@ -73,11 +49,9 @@ int main() {
7349
}
7450
EOF
7551

76-
cat << EOF > internals/CMakeLists.txt
52+
add-file internals/CMakeLists.txt << EOF
7753
add_conventional_executable_tests(PRIVATE message_v1 testing_v1)
7854
7955
add_conventional_executable(hello)
8056
target_link_libraries(hello PRIVATE message_v1)
8157
EOF
82-
83-
git add internals provides

commands/init-library

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash -e
2+
3+
# shellcheck source=init
4+
. "${BASH_SOURCE%/*}/init"
5+
6+
if [ -z "$VERSION" ]; then
7+
FULL_NAME="${NAME}"
8+
else
9+
FULL_NAME="${NAME}_${VERSION}"
10+
fi
11+
12+
# Library boilerplate
13+
14+
add-file provides/CMakeLists.txt << EOF
15+
add_conventional_library($FULL_NAME)
16+
EOF
17+
18+
add-file "provides/include/$FULL_NAME/synopsis.hpp" << EOF
19+
#pragma once
20+
21+
namespace $FULL_NAME {
22+
23+
// TODO
24+
25+
}
26+
EOF
27+
28+
# Testing boilerplate
29+
30+
add-file internals/CMakeLists.txt << EOF
31+
add_conventional_executable_tests(PRIVATE $FULL_NAME)
32+
EOF
33+
34+
add-file internals/testing/compile_synopsis_test.cpp << EOF
35+
#include "$FULL_NAME/synopsis.hpp"
36+
37+
int main() { return 0; }
38+
EOF

0 commit comments

Comments
 (0)