Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Format

on:
pull_request:

permissions:
contents: read

jobs:
clang-format:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format

- name: Check formatting
run: |
git ls-files -z '*.cpp' '*.h' | xargs -0 clang-format --dry-run --Werror
2 changes: 1 addition & 1 deletion src/command_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <cerrno>
#include <cstring>
#include <string>
#include <sys/wait.h>
#include <unistd.h>
#include <vector>
#include <sys/wait.h>

CommandResult runCommand(const std::vector<std::string> &args) {
CommandResult result{1, ""};
Expand Down
4 changes: 1 addition & 3 deletions src/exit_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ enum class ExitCode : int {
kUnresolved = 4,
};

inline int toExitCode(ExitCode code) {
return static_cast<int>(code);
}
inline int toExitCode(ExitCode code) { return static_cast<int>(code); }

inline ExitCode classifySignalErrno(int errorNumber) {
if (errorNumber == EPERM) {
Expand Down
7 changes: 3 additions & 4 deletions src/free_command.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "free_command.h"
#include "cli_constants.h"
#include "exit_codes.h"
#include "free_command.h"
#include "free_options.h"
#include "port_inspection.h"
#include "process_actions.h"
Expand Down Expand Up @@ -190,9 +190,8 @@ int runFreeCommand(int argc, char *argv[]) {
return toExitCode(ExitCode::kOk);
}

ConfirmResult gracefulConfirm =
confirmAction("Send SIG" + gracefulName + " to PIDs " + joinPids(initialPids) + "?",
options.yes);
ConfirmResult gracefulConfirm = confirmAction(
"Send SIG" + gracefulName + " to PIDs " + joinPids(initialPids) + "?", options.yes);
if (gracefulConfirm == ConfirmResult::kRequiresYes) {
return toExitCode(ExitCode::kUsage);
}
Expand Down
5 changes: 2 additions & 3 deletions src/list_command.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "exit_codes.h"
#include "list_command.h"
#include "command_exec.h"
#include "exit_codes.h"
#include "table_output.h"
#include "usage.h"

Expand Down Expand Up @@ -167,8 +167,7 @@ int runListCommand(int argc, char *argv[]) {
rows.reserve(listeners.size());
for (const auto &listener : listeners) {
std::string portText = listener.port > 0 ? std::to_string(listener.port) : "unknown";
rows.push_back(
{portText, listener.pid, listener.user, listener.command, listener.endpoint});
rows.push_back({portText, listener.pid, listener.user, listener.command, listener.endpoint});
}
std::cout << renderTable({"PORT", "PID", "USER", "PROCESS", "ENDPOINT"}, rows) << "\n";

Expand Down
8 changes: 4 additions & 4 deletions src/port_inspection.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "port_inspection.h"
#include "command_exec.h"

#include <cctype>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <stdexcept>
#include <vector>
Expand Down Expand Up @@ -52,8 +52,7 @@ static bool sortByPidThenEndpoint(const ListenerInfo &a, const ListenerInfo &b)
}

static bool sameListener(const ListenerInfo &a, const ListenerInfo &b) {
return a.pid == b.pid && a.user == b.user && a.command == b.command &&
a.endpoint == b.endpoint;
return a.pid == b.pid && a.user == b.user && a.command == b.command && a.endpoint == b.endpoint;
}

static std::vector<ListenerInfo> parseAllListeners(const std::string &raw) {
Expand Down Expand Up @@ -135,7 +134,8 @@ InspectResult inspectPort(int port) {
if (inspect.listeners.empty()) {
inspect.status = InspectStatus::kError;
inspect.error = "Port " + std::to_string(port) +
" appears occupied, but listener parsing failed.\nRaw lsof fields:\n" + result.output;
" appears occupied, but listener parsing failed.\nRaw lsof fields:\n" +
result.output;
return inspect;
}

Expand Down
2 changes: 1 addition & 1 deletion src/usage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "cli_constants.h"
#include "usage.h"
#include "cli_constants.h"

#include <iostream>

Expand Down
2 changes: 1 addition & 1 deletion src/who_command.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "exit_codes.h"
#include "who_command.h"
#include "exit_codes.h"
#include "port_inspection.h"
#include "table_output.h"
#include "types.h"
Expand Down
7 changes: 3 additions & 4 deletions tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ void expectTrue(bool condition, const std::string &name) {
}
}

template <typename T>
void expectEq(const T &actual, const T &expected, const std::string &name) {
template <typename T> void expectEq(const T &actual, const T &expected, const std::string &name) {
if (!(actual == expected)) {
std::cerr << "FAIL: " << name << " (expected: " << expected << ", actual: " << actual << ")\n";
++g_failures;
Expand Down Expand Up @@ -49,8 +48,8 @@ void testParsePort() {
void testParseFreeOptions() {
FreeOptions options;
std::string error;
bool ok = parseFreeOptionsFrom({"portctrl", "free", "3000", "--apply", "--signal", "INT", "--yes"},
options, error);
bool ok = parseFreeOptionsFrom(
{"portctrl", "free", "3000", "--apply", "--signal", "INT", "--yes"}, options, error);
expectTrue(ok, "parseFreeOptions valid input");
expectTrue(options.apply, "parseFreeOptions apply");
expectTrue(options.yes, "parseFreeOptions yes");
Expand Down