summaryrefslogtreecommitdiff
path: root/hscript/util.hh
blob: 47da0224da19f81d6cf75b9daaa089f3d28289fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * util.cc - Definition of useful utility routines
 * libhscript, the HorizonScript library for
 * Project Horizon
 *
 * Copyright (c) 2019 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#ifndef HSCRIPT_UTIL_HH
#define HSCRIPT_UTIL_HH

#include <string>
#include <vector>

/*! Download the contents of a URL to a path.
 * @param url       The URL to download.
 * @param path      The path in which to save the file.
 * @returns true if successful download, false otherwise.
 */
bool download_file(const std::string &url, const std::string &path);

/*! Run a command.
 * @param cmd       The command to run.
 * @param args      Arguments to pass to the command.
 * @returns 0 if the command exited normally with status 0,
 * the exit code if the command exited abnormally,
 * -1 if the command signalled.
 * @note Status of the command is output using +output_error+.
 */
int run_command(const std::string &cmd, const std::vector<std::string> &args);

#endif /* !HSCRIPT_UTIL_HH */