Skip to content

Commit 84c7b2f

Browse files
Refactor/clang style (#175)
1 parent 8dc2165 commit 84c7b2f

26 files changed

Lines changed: 1251 additions & 1172 deletions

.clang-format

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
BasedOnStyle: Google
2-
PointerAlignment: Right
3-
DerivePointerAlignment: false
4-
ColumnLimit: 100
1+
BasedOnStyle: LLVM
52
IndentWidth: 4
3+
ColumnLimit: 100
64
AccessModifierOffset: -4
5+
AllowShortFunctionsOnASingleLine: InlineOnly
76
IncludeBlocks: Regroup
87
IncludeIsMainRegex: '([-_]test)?$'
98
IncludeCategories:
@@ -13,8 +12,3 @@ IncludeCategories:
1312
Priority: 1
1413
- Regex: '^"'
1514
Priority: 3
16-
ReflowComments: true
17-
BreakBeforeBraces: Attach
18-
Cpp11BracedListStyle: true
19-
AllowShortFunctionsOnASingleLine: InlineOnly
20-
SortIncludes: true

.clang-tidy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ Checks: >
1515
readability-container-size-empty
1616
WarningsAsErrors: "*"
1717
FormatStyle: file
18+
CheckOptions:
19+
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
20+
- { key: readability-identifier-naming.MethodCase, value: CamelCase }
21+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
22+
- { key: readability-identifier-naming.StructCase, value: CamelCase }
23+
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
24+
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
25+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
26+
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
27+
- { key: readability-identifier-naming.MemberCase, value: lower_case }
28+
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
29+
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
30+
- { key: readability-identifier-naming.ConstantCase, value: lower_case }

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
- "Dockerfile.musl"
1515

1616
permissions:
17-
contents: write
17+
contents: read
1818

1919
jobs:
2020
build:

.github/workflows/release.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ permissions:
1010
jobs:
1111
release_binaries:
1212
runs-on: ubuntu-24.04
13+
outputs:
14+
version: ${{ steps.version.outputs.version }}
1315
steps:
1416
- name: Checkout code
1517
uses: actions/checkout@v6
1618

19+
- name: Resolve release version
20+
id: version
21+
run: echo "version=$(make get_project_version)" >> "$GITHUB_OUTPUT"
22+
1723
- name: Download Linux GLIBC binary
1824
uses: actions/download-artifact@v8
1925
with:
@@ -39,13 +45,14 @@ jobs:
3945
with:
4046
name: mpqcli-windows-amd64.exe
4147

42-
- name: Extract latest changelog section
48+
- name: Extract changelog for this tag
4349
id: changelog
4450
run: |
45-
CHANGELOG_CONTENT=$(awk '/^## /{i++} i==1{print}' CHANGELOG.md | tail -n +2)
46-
echo "content<<EOF" >> $GITHUB_OUTPUT
47-
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
48-
echo "EOF" >> $GITHUB_OUTPUT
51+
{
52+
echo "content<<EOF"
53+
make get_changelog TAG="${{ steps.version.outputs.version }}"
54+
echo "EOF"
55+
} >> "$GITHUB_OUTPUT"
4956
5057
- name: Release package
5158
run: |
@@ -74,17 +81,13 @@ jobs:
7481
run: |
7582
docker load -i mpqcli-docker.tar
7683
77-
- name: Extract version without "v"
78-
id: version
79-
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
80-
8184
- name: Tag Docker image with version
8285
run: |
83-
docker tag mpqcli ghcr.io/thegraydot/mpqcli:${{ env.VERSION }}
86+
docker tag mpqcli ghcr.io/thegraydot/mpqcli:${{ needs.release_binaries.outputs.version }}
8487
docker tag mpqcli ghcr.io/thegraydot/mpqcli:latest
8588
8689
- name: Push Docker image to GitHub Container Registry
8790
run: |
8891
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
89-
docker push ghcr.io/thegraydot/mpqcli:${{ env.VERSION }}
92+
docker push ghcr.io/thegraydot/mpqcli:${{ needs.release_binaries.outputs.version }}
9093
docker push ghcr.io/thegraydot/mpqcli:latest

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call
55

66
permissions:
7-
contents: write
7+
contents: read
88

99
jobs:
1010
test_linux:

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
## 0.10.1 - 2026-07-03
4+
5+
### Added
6+
7+
- Command completion for common shells (bash, zsh, fish and powershell)
8+
9+
### Fixed
10+
11+
- Memory leak in read subcommand
12+
- Inconsistencies in documentation
13+
14+
### Updated
15+
16+
- Code style to conform to Google CPP style with slight variations
17+
- StormLib dependency for a variety of fixes
18+
19+
### Thanks
20+
21+
- Thanks to @sjoblomj for the contributions in this release
22+
323
## 0.10.0 - 2026-06-07
424

525
### Added

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
project(MPQCLI VERSION 0.10.0)
3+
project(MPQCLI VERSION 0.10.1)
44

55
# Options
66
option(BUILD_MPQCLI "Build the mpqcli CLI app" ON)
@@ -25,11 +25,17 @@ if(BUILD_STATIC)
2525
endif()
2626

2727
# Determine git commit hash
28-
execute_process (
28+
execute_process(
2929
COMMAND git rev-parse HEAD
30+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
3031
OUTPUT_STRIP_TRAILING_WHITESPACE
3132
OUTPUT_VARIABLE GIT_COMMIT_HASH
33+
RESULT_VARIABLE GIT_COMMIT_RESULT
34+
ERROR_QUIET
3235
)
36+
if(NOT GIT_COMMIT_RESULT EQUAL 0 OR NOT GIT_COMMIT_HASH)
37+
set(GIT_COMMIT_HASH "unknown")
38+
endif()
3339

3440
# Handle StormLib dependency
3541
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/StormLib/CMakeLists.txt")

CONTRIBUTING.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Run `make help` to list all available targets. Common ones:
3131
| Target | Description |
3232
|----------------------------|--------------------------------------------------------------------|
3333
| `make install_clang_tools` | Install clang-format and clang-tidy via apt |
34+
| `make configure` | Configure cmake build with clang (required before `make lint`) |
3435
| `make build_linux` | Build for Linux using cmake |
3536
| `make build_windows` | Build for Windows using cmake |
3637
| `make build_clean` | Remove the cmake build directory |
@@ -72,9 +73,10 @@ If your change adds or modifies user-facing functionality - such as a new subcom
7273

7374
### 4. Linting must pass
7475

75-
All C++ code is formatted with clang-format and analysed with clang-tidy. Run the full suite before submitting:
76+
All C++ code is formatted with clang-format and analysed with clang-tidy. `clang-tidy` needs a compile database generated with clang, so run `make configure` first (`make build_linux`/`make build_windows` alone will not work, since they don't set up the compiler flags clang-tidy needs):
7677

7778
```
79+
make configure
7880
make lint
7981
```
8082

@@ -88,7 +90,7 @@ Then re-run `make lint` to confirm everything passes.
8890

8991
### 5. Match the existing code style
9092

91-
C++ formatting is enforced by `.clang-format` (Google style base). Static analysis is enforced by `.clang-tidy`. Both configs live in the repo root. Python tests should follow the style of the existing test files.
93+
C++ formatting is enforced by `.clang-format` (LLVM style base). Static analysis is enforced by `.clang-tidy`. Both configs live in the repo root. Python tests should follow the style of the existing test files.
9294

9395
#### Suppression policy
9496

@@ -106,7 +108,8 @@ Suppressions are occasionally necessary for third-party code or intentional patt
106108
Use `// clang-format off` / `// clang-format on` only when the default formatting genuinely hurts readability (e.g. column-aligned tables). Add a brief comment explaining the intent:
107109

108110
```cpp
109-
// clang-format off: preserve column-aligned flag-to-char mappings for readability
111+
// Preserve column-aligned flag-to-char mappings for readability
112+
// clang-format off
110113
if (flags & MPQ_FILE_IMPLODE) result += 'i';
111114
if (flags & MPQ_FILE_COMPRESS) result += 'c';
112115
// clang-format on
@@ -131,6 +134,6 @@ If you add a new StormLib call that is locale-sensitive, follow the existing pat
131134
2. Run `git submodule update --init --recursive` after cloning
132135
3. Run `make install_clang_tools` to install lint dependencies
133136
4. Make your changes and verify they build: `make build_linux`
134-
5. Run `make lint` and fix any issues
137+
5. Run `make configure` and then `make lint`, fixing any issues
135138
6. Run `make test_mpqcli` and confirm all tests pass
136139
7. Open a pull request with a clear description of what was changed and why

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![Release Version](https://img.shields.io/github/v/release/thegraydot/mpqcli?style=flat)
66

7-
![Release downloads](https://img.shields.io/github/downloads/thegraydot/mpqcli/total?label=release_downloads) ![Package downloads](https://img.shields.io/badge/package_downloads-894-green)
7+
![Release downloads](https://img.shields.io/github/downloads/thegraydot/mpqcli/total?label=release_downloads) ![Package downloads](https://img.shields.io/badge/package_downloads-996-green)
88

99
A command-line tool to create, add, remove, list, extract, read, and verify MPQ archives using the [StormLib library](https://github.com/ladislav-zezula/StormLib).
1010

docs/commands/completion.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ source ~/.bash_completion.d/mpqcli
2121
Alternatively, write the script to a system-wide completions directory (requires root):
2222

2323
```bash
24-
$ mpqcli completion bash > /etc/bash_completion.d/mpqcli
24+
$ mpqcli completion bash | sudo tee /etc/bash_completion.d/mpqcli > /dev/null
2525
```
2626

2727
## Zsh
@@ -32,18 +32,18 @@ Write the completion script to a directory that is on your `$fpath`.
3232
$ mpqcli completion zsh > "${fpath[1]}/_mpqcli"
3333
```
3434

35-
## PowerShell
36-
37-
Append the completion script to your PowerShell profile so it loads automatically.
38-
39-
```powershell
40-
PS> mpqcli completion powershell >> $PROFILE
41-
```
42-
4335
## Fish
4436

4537
Write the completion script to the fish completions directory.
4638

4739
```fish
4840
$ mpqcli completion fish > ~/.config/fish/completions/mpqcli.fish
4941
```
42+
43+
## PowerShell
44+
45+
Append the completion script to your PowerShell profile so it loads automatically.
46+
47+
```powershell
48+
PS> mpqcli completion powershell >> $PROFILE
49+
```

0 commit comments

Comments
 (0)