Skip to content

Commit

Permalink
Refactor into two programs.
Browse files Browse the repository at this point in the history
  • Loading branch information
acodcha committed Sep 27, 2023
1 parent 518a488 commit 317a206
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 144 deletions.
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ FetchContent_Declare(
FetchContent_MakeAvailable(yaml-cpp)
message(STATUS "The yaml-cpp library was fetched from: https://github.com/jbeder/yaml-cpp.git")

# Define the main Secret Santa executable.
add_executable(secret-santa ${PROJECT_SOURCE_DIR}/source/Main.cpp)
target_link_libraries(secret-santa PUBLIC stdc++fs yaml-cpp)
# Define the Secret Santa Randomizer executable.
add_executable(secret-santa-randomizer ${PROJECT_SOURCE_DIR}/source/Randomizer/Main.cpp)
target_link_libraries(secret-santa-randomizer PUBLIC stdc++fs yaml-cpp)

# Define the Secret Santa Messenger executable.
add_executable(secret-santa-messenger ${PROJECT_SOURCE_DIR}/source/Messenger/Main.cpp)
target_link_libraries(secret-santa-messenger PUBLIC stdc++fs yaml-cpp)

# Configure the Secret Santa tests.
if(TEST_SECRET_SANTA)
Expand All @@ -85,9 +89,13 @@ if(TEST_SECRET_SANTA)

# Define the Secret Santa test executables.

add_executable(settings ${PROJECT_SOURCE_DIR}/test/Settings.cpp)
target_link_libraries(settings GTest::gtest_main)
gtest_discover_tests(settings)
add_executable(messenger_settings ${PROJECT_SOURCE_DIR}/test/Messenger/Settings.cpp)
target_link_libraries(messenger_settings GTest::gtest_main)
gtest_discover_tests(messenger_settings)

add_executable(randomizer_settings ${PROJECT_SOURCE_DIR}/test/Randomizer/Settings.cpp)
target_link_libraries(randomizer_settings GTest::gtest_main)
gtest_discover_tests(randomizer_settings)

add_executable(string ${PROJECT_SOURCE_DIR}/test/String.cpp)
target_link_libraries(string GTest::gtest_main)
Expand Down
65 changes: 47 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Organizes a "Secret Santa" gift exchange event! Given a list of participant name
- [Configuration](#configuration)
- [Email](#configuration-email)
- [S-Nail Package](#configuration-s-nail-package)
- [Secret Santa Executable](#configuration-secret-santa-executable)
- [Secret Santa Executables](#configuration-secret-santa-executables)
- [Usage](#usage)
- [Command-Line](#usage-command-line)
- [Secret Santa Randomizer](#usage-secret-santa-randomizer)
- [Secret Santa Messenger](#usage-secret-santa-messenger)
- [Configuration File](#usage-configuration-file)
- [Results File](#usage-results-file)
- [Matchings File](#usage-matchings-file)
- [Testing](#testing)
- [License](#license)

Expand All @@ -30,7 +31,7 @@ Additionally, the _yaml-cpp_ library (<https://github.com/jbeder/yaml-cpp>) is u

- [Email](#configuration-email)
- [S-Nail Package](#configuration-s-nail-package)
- [Secret Santa Executable](#configuration-secret-santa-executable)
- [Secret Santa Executables](#configuration-secret-santa-executables)

[(Back to Top)](#secret-santa)

Expand Down Expand Up @@ -79,7 +80,7 @@ Again, replace `myusername` with your email address. This should send a short em

[(Back to Configuration)](#configuration)

### Configuration: Secret Santa Executable
### Configuration: Secret Santa Executables

Clone this project's repository and configure it with:

Expand All @@ -92,50 +93,78 @@ cmake ..
make --jobs=16
```

This builds the main executable, `build/bin/secret-santa`.
This builds the main executables:

- `build/bin/secret-santa-randomizer`
- `build/bin/secret-santa-messenger`

[(Back to Configuration)](#configuration)

## Usage

- [Command-Line](#usage-command-line)
- [Configuration File](#usage-configuration-file)
- [Results File](#usage-results-file)
- [Secret Santa Randomizer](#usage-secret-santa-randomizer)
- [Matchings File](#usage-matchings-file)
- [Secret Santa Messenger](#usage-secret-santa-messenger)

[(Back to Top)](#secret-santa)

### Usage: Command-Line
### Usage: Configuration File

TODO.

[(Back to Usage)](#usage)

Print usage information to the console by running the main executable from the `build` directory with:
### Usage: Secret Santa Randomizer

The Secret Santa Randomizer reads a YAML configuration file containing a list of participants, randomly generates Secret Santa matchings among the participants, and outputs the matchings to a YAML file.

Print usage information to the console by running the Secret Santa Randomizer executable from the `build` directory with:

```bash
bin/secret-santa --help
bin/secret-santa-randomizer --help
```

Run the main executable from the `build` directory with:
Run the Secret Santa Randomizer executable from the `build` directory with:

```bash
bin/secret-santa --configuration <path> [--results <path>] [--email] [--seed <integer>]
bin/secret-santa-randomizer --configuration <path> [--matchings <path>] [--seed <integer>]
```

The command-line arguments are:

- `--configuration <path>`: Path to the YAML configuration file to be read. Required.
- `--results <path>`: Path to the YAML results file to be written. Optional. If omitted, no results file is written.
- `--email`: Whether or not to email instructions to each participant. Optional. If omitted, instructions are not emailed to any participant.
- `--matchings <path>`: Path to the YAML matchings file to be written. Optional. If omitted, no matchings file is written.
- `--seed <integer>`: Seed value for pseudo-random number generation. If omitted, the seed value is randomized.

[(Back to Usage)](#usage)

### Usage: Configuration File
### Usage: Matchings File

TODO.

[(Back to Usage)](#usage)

### Usage: Results File
### Usage: Secret Santa Messenger

TODO.
The Secret Santa Messenger reads a YAML configuration file containing a list of participants and the YAML matchings file generated by the Secret Santa Randomizer and sends email messages to each participant informing them of their assigned giftee and containing instructions for the Secret Santa event.

Print usage information to the console by running the Secret Santa Messenger executable from the `build` directory with:

```bash
bin/secret-santa-messenger --help
```

Run the Secret Santa Messenger executable from the `build` directory with:

```bash
bin/secret-santa-messenger --configuration <path> --matchings <path>
```

The command-line arguments are:

- `--configuration <path>`: Path to the YAML configuration file to be read. Required.
- `--matchings <path>`: Path to the YAML matchings file to be read. Required.

[(Back to Usage)](#usage)

Expand Down
70 changes: 70 additions & 0 deletions source/Messenger/Argument.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright © 2023 Alexandre Coderre-Chabot
//
// This file is licensed under the MIT license. For more information, visit:
// https://mit-license.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// - The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// This file was originally obtained from:
// https://github.com/acodcha/secret-santa

#ifndef SECRET_SANTA_MESSENGER_ARGUMENT_HPP
#define SECRET_SANTA_MESSENGER_ARGUMENT_HPP

#include <string>
#include <string_view>

namespace SecretSanta::Messenger::Argument {

namespace Key {

// Prints usage instructions and exits. Optional.
static const std::string Help{"--help"};

// Path to the YAML configuration file to be read. Required.
static const std::string Configuration{"--configuration"};

// Path to the YAML matchings file to be read. Required.
static const std::string Matchings{"--matchings"};

} // namespace Key

namespace Value {

// Filesystem path.
static const std::string Path{"<path>"};

} // namespace Value

// Prints usage instructions and exits. Optional.
std::string_view Help() {
return Key::Help;
}

// Path to the YAML configuration file to be read. Required.
std::string Configuration() {
return Key::Configuration + " " + Value::Path;
}

// Path to the YAML matchings file to be read. Required.
std::string Matchings() {
return Key::Matchings + " " + Value::Path;
}

} // namespace SecretSanta::Messenger::Argument

#endif // SECRET_SANTA_MESSENGER_ARGUMENT_HPP
5 changes: 3 additions & 2 deletions source/Main.cpp → source/Messenger/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
#include "Settings.hpp"

int main(int argc, char* argv[]) {
const SecretSanta::Settings settings{argc, argv};
const SecretSanta::Messenger::Settings settings{argc, argv};

std::cout << "End of program." << std::endl;
std::cout << "End of " << SecretSanta::Messenger::Program::Title << "."
<< std::endl;

return EXIT_SUCCESS;
}
49 changes: 49 additions & 0 deletions source/Messenger/Program.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2023 Alexandre Coderre-Chabot
//
// This file is licensed under the MIT license. For more information, visit:
// https://mit-license.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// - The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// This file was originally obtained from:
// https://github.com/acodcha/secret-santa

#ifndef SECRET_SANTA_MESSENGER_PROGRAM_HPP
#define SECRET_SANTA_MESSENGER_PROGRAM_HPP

#include <string>

namespace SecretSanta::Messenger::Program {

// Title of the Secret Santa Messenger program.
static const std::string Title{"Secret Santa Messenger"};

// Date and time at which the Secret Santa Messenger program was compiled.
static const std::string CompilationDateAndTime{
std::string{__DATE__} + ", " + std::string{__TIME__}};

// Description of the Secret Santa Messenger program.
static const std::string Description{
"Organizes a \"Secret Santa\" gift exchange event! Reads a YAML "
"configuration file containing a list of participants and the YAML "
"matchings file generated by the Secret Santa Randomizer and sends email "
"messages to each participant informing them of their assigned giftee and "
"containing instructions for the Secret Santa event."};

} // namespace SecretSanta::Messenger::Program

#endif // SECRET_SANTA_MESSENGER_PROGRAM_HPP
Loading

0 comments on commit 317a206

Please sign in to comment.