diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0451da0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -8 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: TopLevel +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 4 +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 8 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +QualifierAlignment: Left +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 8 +UseTab: ForContinuationAndIndentation diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..53466ac --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,31 @@ +Checks: >- + bugprone-*, + cppcoreguidelines-*, + google-*, + misc-*, + modernize-*, + performance-*, + readability-*, + -bugprone-lambda-function-name, + -bugprone-easily-swappable-parameters, + -bugprone-reserved-identifier, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-vararg, + -google-readability-braces-around-statements, + -google-readability-function-size, + -misc-no-recursion, + -modernize-return-braced-init-list, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -performance-unnecessary-value-param, + -readability-identifier-length, + -readability-magic-numbers + +CheckOptions: + readability-function-cognitive-complexity.Threshold: 100 + readability-function-cognitive-complexity.IgnoreMacros: true + readability-identifier-naming.ClassCase: CamelCase diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9845628 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/sgard.iml b/.idea/sgard.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/sgard.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 0000000..1e24652 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,8 @@ +*out +*logs +*actions +*notifications +*tools +plugins +user_trunk.yaml +user.yaml diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc new file mode 100644 index 0000000..8c7b1ad --- /dev/null +++ b/.trunk/configs/.shellcheckrc @@ -0,0 +1,7 @@ +enable=all +source-path=SCRIPTDIR +disable=SC2154 + +# If you're having issues with shellcheck following source, disable the errors via: +# disable=SC1090 +# disable=SC1091 diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml new file mode 100644 index 0000000..4d44466 --- /dev/null +++ b/.trunk/configs/.yamllint.yaml @@ -0,0 +1,10 @@ +rules: + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 0000000..fff3f81 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,34 @@ +# This file controls the behavior of Trunk: https://docs.trunk.io/cli +# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml +version: 0.1 +cli: + version: 1.17.1 +plugins: + sources: + - id: trunk + ref: v1.2.6 + uri: https://github.com/trunk-io/plugins +runtimes: + enabled: + - go@1.21.0 + - node@18.12.1 + - python@3.10.8 +lint: + enabled: + - checkov@2.5.9 + - clang-format@16.0.3 + - clang-tidy@16.0.3 + - git-diff-check + - prettier@3.0.3 + - shellcheck@0.9.0 + - shfmt@3.6.0 + - trivy@0.46.0 + - trufflehog@3.60.0 + - yamllint@1.32.0 +actions: + disabled: + - trunk-announce + - trunk-check-pre-push + - trunk-fmt-pre-commit + enabled: + - trunk-upgrade-available diff --git a/proto/header.proto b/proto/header.proto index b8cb3bf..1484927 100644 --- a/proto/header.proto +++ b/proto/header.proto @@ -4,8 +4,9 @@ package sgardpb; import "google/protobuf/timestamp.proto"; // Header defines common metadata for messages in sgard. -message Header { - uint32 version = 1; +message Header +{ + uint32 version = 1; google.protobuf.Timestamp created = 2; google.protobuf.Timestamp updated = 3; } diff --git a/proto/homedir.proto b/proto/homedir.proto index a2a8da4..88d9a91 100644 --- a/proto/homedir.proto +++ b/proto/homedir.proto @@ -4,7 +4,8 @@ package sgardpb; import 'header.proto'; import 'path.proto'; -message HomeDir { +message HomeDir +{ Header header = 1; map files = 5; diff --git a/proto/path.proto b/proto/path.proto index 8b388d3..6671208 100644 --- a/proto/path.proto +++ b/proto/path.proto @@ -6,26 +6,28 @@ import "google/protobuf/timestamp.proto"; enum PathType { PATHTYPE_UNSPECIFIED = 0; - PATHTYPE_FILE = 1; - PATHTYPE_DIRECTORY = 2; - PATHTYPE_LINK = 3; + PATHTYPE_FILE = 1; + PATHTYPE_DIRECTORY = 2; + PATHTYPE_LINK = 3; }; -message FilePath { +message FilePath +{ Header header = 1; string source_path = 2; - string dest_path = 3; + string dest_path = 3; // todo: add mode, action (e.g. copy vs link) }; -message Source { - Header header = 1; +message Source +{ + Header header = 1; PathType path_type = 2; - oneof path { + oneof path + { FilePath file = 5; }; }; - diff --git a/scripts/install-depdendencies.sh b/scripts/install-depdendencies.sh index d043163..9719466 100755 --- a/scripts/install-depdendencies.sh +++ b/scripts/install-depdendencies.sh @@ -15,7 +15,7 @@ set -eu -install_debianesque () { +install_debianesque() { echo "[+] distribution is ${DISTRIB_ID}, choosing Debianesque install." echo "[+] installing tools" @@ -28,7 +28,7 @@ install_debianesque () { sudo apt-get install protobuf-compiler-grpc grpc-proto libgrpc++-dev } -install_redhat () { +install_redhat() { echo "[+] distribution is ${DISTRIB_ID}, choosing Redhat install." echo "[!] WARNING: installation for Redhat systems is unverified." @@ -39,7 +39,7 @@ install_redhat () { sudo dnf install protobuf-compiler libprotobuf-dev } -install_alpine () { +install_alpine() { echo "[+] distribution is ${DISTRIB_ID}, choosing Alpine install." echo "[!] WARNING: installation for Alpine systems is unverified." @@ -50,7 +50,7 @@ install_alpine () { sudo dnf install sdl2-dev freetype-dev protobuf-compiler-grpc } -install_macos () { +install_macos() { # TODO: consider supporting macports? echo "[+] host system is MacOS" @@ -61,20 +61,15 @@ install_macos () { # TODO: look up proper package names in homebrew } - -install_linux () { +install_linux() { echo "[+] host system is Linux" [[ -f "/etc/lsb-release" ]] && source /etc/lsb-release - if [ -z "${DISTRIB_ID}" ] - then - if [ -d /etc/apt ] - then + if [ -z "${DISTRIB_ID}" ]; then + if [ -d /etc/apt ]; then DISTRIB_ID="apt-based" - elif [ -f /etc/alpine-release ] - then + elif [ -f /etc/alpine-release ]; then DISTRIB_ID=Alpine - elif [ -d /etc/dnf -o /etc/yum.repos.d ] - then + elif [ -d /etc/dnf -o /etc/yum.repos.d ]; then # I don't use Fedora, this is based on a cursory # glance at the filesystem on a Docker image. DISTRIB_ID="Fedora" @@ -82,25 +77,22 @@ install_linux () { fi case ${DISTRIB_ID} in - Ubuntu) install_debianesque ;; - Debian) install_debianesque ;; - apt-based) install_debianesque ;; - Fedora) install_redhat ;; - Alpine) install_alpine ;; + Ubuntu) install_debianesque ;; + Debian) install_debianesque ;; + apt-based) install_debianesque ;; + Fedora) install_redhat ;; + Alpine) install_alpine ;; - *) - echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." > /dev/null - ;; + *) + echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." >/dev/null + ;; esac } - case "$(uname -s)" in - Linux) install_linux ;; - Darwin) install_macos ;; - *) - echo "[!] platform $(uname -s) isn't supported in this script." > /dev/null - ;; +Linux) install_linux ;; +Darwin) install_macos ;; +*) + echo "[!] platform $(uname -s) isn't supported in this script." >/dev/null + ;; esac - - diff --git a/sgard.cc b/sgard.cc index 83e6b72..f60bc65 100644 --- a/sgard.cc +++ b/sgard.cc @@ -17,7 +17,7 @@ main(int argc, char *argv[]) auto parseResult = flag->Parse(argc, argv); if (parseResult != scsl::Flags::ParseStatus::OK) { - std::cerr << "failed to parse flags: " + std::cerr << "failed to parse flags: " << scsl::Flags::ParseStatusToString(parseResult) << "\n"; flag->Usage(std::cerr, 1);