cmd::desktop_entry: Print out all recognized keys
This commit is contained in:
parent
fa4c34bd53
commit
1d3cdbe6a1
@ -1,4 +1,5 @@
|
||||
use fmt;
|
||||
use fs;
|
||||
use format::desktop_entry;
|
||||
use getopt;
|
||||
use io;
|
||||
@ -38,10 +39,21 @@ export fn main() void = {
|
||||
os::exit(os::status::FAILURE);
|
||||
};
|
||||
|
||||
// TODO put in function and handle errors here
|
||||
let file = os::open(file_name)!;
|
||||
defer io::close(file)!;
|
||||
let file = desktop_entry::parse(file)!;
|
||||
let file = match (parse_file(file_name)) {
|
||||
case let file: desktop_entry::file =>
|
||||
yield file;
|
||||
case let err: fs::error =>
|
||||
fmt::fprintf(
|
||||
os::stderr, "{}: {}: {}\n",
|
||||
name, file_name, fs::strerror(err))!;
|
||||
os::exit(os::status::FAILURE);
|
||||
case let err: desktop_entry::error =>
|
||||
fmt::fprintf(
|
||||
os::stderr, "{}: {}: {}\n",
|
||||
name, file_name, desktop_entry::strerror(err))!;
|
||||
os::exit(os::status::FAILURE);
|
||||
};
|
||||
|
||||
let result = if (action == "") {
|
||||
yield print_file(file, local);
|
||||
} else {
|
||||
@ -49,13 +61,19 @@ export fn main() void = {
|
||||
};
|
||||
|
||||
match(result) {
|
||||
case let err: desktop_entry::error =>
|
||||
fmt::fprintf(os::stderr, "{}: {}\n", name, desktop_entry::strerror(err))!;
|
||||
case let err: io::error =>
|
||||
fmt::fprintf(os::stderr, "{}: {}\n", name, io::strerror(err))!;
|
||||
case void => void;
|
||||
};
|
||||
};
|
||||
|
||||
fn print_file (file: desktop_entry::file, local: locale::locale) (void | desktop_entry::error) = {
|
||||
fn parse_file (file_name: str) (desktop_entry::file | fs::error | desktop_entry::error) = {
|
||||
let file = os::open(file_name)?;
|
||||
defer io::close(file)!;
|
||||
return desktop_entry::parse(file);
|
||||
};
|
||||
|
||||
fn print_file(file: desktop_entry::file, local: locale::locale) (void | io::error) = {
|
||||
fmt::printf("Type={}\n", file.typ)?;
|
||||
fmt::printf("Version={}\n", file.version)?;
|
||||
match (locale::string_resolve(file.name, local)) {
|
||||
@ -75,11 +93,46 @@ fn print_file (file: desktop_entry::file, local: locale::locale) (void | desktop
|
||||
case let icon: str => if (icon != "") fmt::printf("Icon={}\n", icon)?;
|
||||
case void => void;
|
||||
};
|
||||
// TODO all other keys
|
||||
// https://specifications.freedesktop.org/desktop-entry-spec/latest/recognized-keys.html
|
||||
if (file.hidden) fmt::println("Hidden=true")?;
|
||||
if (file.dbus_activatable) fmt::println("DBusActivatable=true")?;
|
||||
if (file.try_exec != "") fmt::printf("TryExec={}\n", file.try_exec)?;
|
||||
if (file.exec != "") fmt::printf("Exec={}\n", file.exec)?;
|
||||
if (file.path != "") fmt::printf("Path={}\n", file.path)?;
|
||||
if (file.terminal) fmt::println("Terminal=true")?;
|
||||
if (len(file.mime_type) > 0) {
|
||||
fmt::print("MimeType=")?;
|
||||
print_strings(file.mime_type)?;
|
||||
};
|
||||
if (len(file.categories) > 0) {
|
||||
fmt::print("Categories=")?;
|
||||
print_strings(file.categories)?;
|
||||
};
|
||||
if (len(file.implements) > 0) {
|
||||
fmt::print("Implements=")?;
|
||||
print_strings(file.implements)?;
|
||||
};
|
||||
if (len(file.keywords) > 0) {
|
||||
fmt::print("Keywords=")? ;
|
||||
match (locale::strings_resolve(file.keywords, local)) {
|
||||
case let keywords: []str => print_strings(keywords)?;
|
||||
case void => void;
|
||||
};
|
||||
};
|
||||
if (file.startup_notify) fmt::println("StartupNotify=true")?;
|
||||
if (file.startup_wm_class != "") fmt::printf("StartupWMClass={}\n", file.startup_wm_class)?;
|
||||
if (file.url != "") fmt::printf("URL={}\n", file.url)?;
|
||||
if (file.prefers_non_default_gpu) fmt::println("PrefersNonDefaultGPU=true")?;
|
||||
if (file.single_main_window) fmt::println("SingleMainWindow=true")?;
|
||||
};
|
||||
|
||||
fn print_action (file: desktop_entry::file, local: locale::locale, key: str) (void | desktop_entry::error) = {
|
||||
fn print_strings(strings: []str) (void | io::error) = {
|
||||
for (let string .. strings) {
|
||||
fmt::printf("{};", string)?;
|
||||
};
|
||||
fmt::println()?;
|
||||
};
|
||||
|
||||
fn print_action(file: desktop_entry::file, local: locale::locale, key: str) (void | io::error) = {
|
||||
let action: (desktop_entry::action | void) = void;
|
||||
for (let actio .. file.actions) {
|
||||
if (actio.key == key) {
|
||||
|
Loading…
Reference in New Issue
Block a user