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 # 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 ## Features
@ -14,21 +15,22 @@ Display wallpapers on Sway, this is essentially a wrapper for `swaybg`.
## Usage ## Usage
``` ```
usage: sway-wallpaper [options] <path> <output> usage: sway-wallpaper [options] <path>
required: required:
output The outputs as shown with the command `swaymsg -t get_outputs` path The path to the directory containing the wallpapers
path The path to the directory containing the wallpapers
options: options:
-h, --help Show help -h, --help Show help
-i, --interval Specify the interval between wallpapers in seconds -i, --interval Specify the interval between wallpapers in seconds
--never-random if set, wallpapers order is based on the names of the files --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: Example:
`./sway-wallpaper /path/to/wallpapers -i 3600 DP-1` `./sway-wallpaper /path/to/wallpapers -i 3600 -o DP-1`
## Installation ## Installation

View file

@ -40,7 +40,7 @@ namespace CliArguments {
std::string getString(const std::string& argName) const { std::string getString(const std::string& argName) const {
auto value = argumentsValue_.find(argName); auto value = argumentsValue_.find(argName);
if (value == argumentsValue_.end()) { 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; return value->second;
} }
@ -50,7 +50,7 @@ namespace CliArguments {
try { try {
return std::stoi(valueStr); return std::stoi(valueStr);
} catch (std::exception& e) { } 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 { bool getBool(const std::string& argName) const {
auto valueStr = getString(argName); auto valueStr = getString(argName);
if (valueStr != "true" && valueStr != "false") { 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"; return valueStr == "true";
} }

View file

@ -10,8 +10,6 @@
int main(int argc, char** argv, char** envp) { int main(int argc, char** argv, char** envp) {
try { try {
CliArguments::CliArguments arguments{ CliArguments::CliArguments arguments{
argc, argv, argc, argv,
{ {
@ -22,10 +20,9 @@ int main(int argc, char** argv, char** envp) {
.direct = true .direct = true
}}, }},
{"output", { {"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, .type = CliArguments::String,
.order = 1,
.direct = true
}}, }},
{"interval", { {"interval", {
.aliases = {"i"}, .aliases = {"i"},
@ -60,7 +57,7 @@ int main(int argc, char** argv, char** envp) {
} }
const std::string path = arguments.getString("path"); 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); Wallpapers wallpapers(path);