77 lines
2.7 KiB
C++
77 lines
2.7 KiB
C++
/*
|
|
Copyright (C) 2021 Greg S.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
*/
|
|
#include <string>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <system_error>
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include <sys/xattr.h>
|
|
|
|
#include <ss4sc/file-utils.hpp>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
using boost::program_options::value;
|
|
|
|
boost::program_options::options_description desc("Attribute options");
|
|
desc.add_options()
|
|
("help", "produce this help message")
|
|
("content-type", value<std::string>(), "set the user.mime_type extended attribute")
|
|
("charset", value<std::string>(), "set the user.charset extended attribute")
|
|
("language", value<std::string>(), "set the user.xdg.language extended attribute")
|
|
("encoding", value<std::string>(), "set the user.mime_encoding extended attribute")
|
|
("extra-header", "set an additional header into user.e6l.ss4sc_headers")
|
|
("file-path", value<std::vector<std::string>>(), "the file to manipulate")
|
|
;
|
|
|
|
boost::program_options::positional_options_description pdesc;
|
|
pdesc.add("file-path", -1);
|
|
|
|
boost::program_options::variables_map vm;
|
|
boost::program_options::store(
|
|
boost::program_options::command_line_parser(argc, argv)
|
|
.options(desc).positional(pdesc).run(),
|
|
vm
|
|
);
|
|
boost::program_options::notify(vm);
|
|
|
|
if(vm.count("help") || vm.count("file-path") < 1 ) {
|
|
std::cerr << desc << "\n";
|
|
return 2;
|
|
}
|
|
|
|
for( auto stringpath : vm["file-path"].as<std::vector<std::string>>() ) {
|
|
if( vm.count("content-type") == 1 ) {
|
|
set_file_attr(stringpath, attr_mimetype, vm["content-type"].as<std::string>());
|
|
}
|
|
|
|
if( vm.count("charset") == 1 ) {
|
|
set_file_attr(stringpath, attr_charset, vm["charset"].as<std::string>());
|
|
}
|
|
|
|
if( vm.count("language") == 1 ) {
|
|
set_file_attr(stringpath, attr_language, vm["language"].as<std::string>());
|
|
}
|
|
|
|
if( vm.count("encoding") == 1 ) {
|
|
set_file_attr(stringpath, attr_encoding, vm["encoding"].as<std::string>());
|
|
}
|
|
|
|
}
|
|
}
|