Make --output parameter optional

This commit is contained in:
Vyn 2024-06-06 11:57:38 +02:00
parent fe4e18f3b5
commit fd6ece0041
3 changed files with 16 additions and 17 deletions

View file

@ -1,6 +1,7 @@
# Sway Wallpaper
Display wallpapers on Sway, this is essentially a wrapper for `swaybg`.
Display wallpapers on Sway, this is essentially a wrapper for `swaybg` and `swaylock`, they are
required to run this utility.
## Features
@ -14,21 +15,22 @@ Display wallpapers on Sway, this is essentially a wrapper for `swaybg`.
## Usage
```
usage: sway-wallpaper [options] <path> <output>
usage: sway-wallpaper [options] <path>
required:
output The outputs as shown with the command `swaymsg -t get_outputs`
path The path to the directory containing the wallpapers
options:
-h, --help Show help
-i, --interval Specify the interval between wallpapers in seconds
--lock Lock the screen using swaylock instead of applying a wallpaper
--never-random if set, wallpapers order is based on the names of the files
-o, --output The outputs as shown with the command `swaymsg -t get_outputs`, by default the wallpaper will be applied to all outputs
```
Example:
`./sway-wallpaper /path/to/wallpapers -i 3600 DP-1`
`./sway-wallpaper /path/to/wallpapers -i 3600 -o DP-1`
## Installation

View file

@ -40,7 +40,7 @@ namespace CliArguments {
std::string getString(const std::string& argName) const {
auto value = argumentsValue_.find(argName);
if (value == argumentsValue_.end()) {
throw std::logic_error("trying to access non existant argument '" + argName + "'");
throw std::logic_error("CliArguments Error: trying to access non existant argument '" + argName + "'");
}
return value->second;
}
@ -50,7 +50,7 @@ namespace CliArguments {
try {
return std::stoi(valueStr);
} catch (std::exception& e) {
throw std::logic_error("trying to access argument '" + argName + "' (value: '" + valueStr + "')" + " as integer");
throw std::logic_error("CliArguments Error: trying to access argument '" + argName + "' (value: '" + valueStr + "')" + " as integer");
}
}
@ -67,7 +67,7 @@ namespace CliArguments {
bool getBool(const std::string& argName) const {
auto valueStr = getString(argName);
if (valueStr != "true" && valueStr != "false") {
throw std::logic_error("trying to access argument '" + argName + "' (value: '" + valueStr + "')" + " as bool");
throw std::logic_error("CliArguments Error: trying to access argument '" + argName + "' (value: '" + valueStr + "')" + " as bool");
}
return valueStr == "true";
}

View file

@ -10,8 +10,6 @@
int main(int argc, char** argv, char** envp) {
try {
CliArguments::CliArguments arguments{
argc, argv,
{
@ -22,10 +20,9 @@ int main(int argc, char** argv, char** envp) {
.direct = true
}},
{"output", {
.description = "The outputs as shown with the command `swaymsg -t get_outputs`",
.aliases = {"o"},
.description = "The outputs as shown with the command `swaymsg -t get_outputs`, by default the wallpaper will be applied to all outputs",
.type = CliArguments::String,
.order = 1,
.direct = true
}},
{"interval", {
.aliases = {"i"},
@ -60,7 +57,7 @@ int main(int argc, char** argv, char** envp) {
}
const std::string path = arguments.getString("path");
const std::string output = arguments.getString("output");
const std::string output = arguments.exists("output") ? arguments.getString("output") : "*";
Wallpapers wallpapers(path);