-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6738abb
commit ce19b4f
Showing
6 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2019-2023 tsurugi project. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <iostream> | ||
|
||
#include <boost/property_tree/ptree.hpp> | ||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS // to retain the current behavior | ||
#include <boost/property_tree/json_parser.hpp> | ||
#include <boost/filesystem/operations.hpp> | ||
|
||
#include "tateyama/process/process.h" | ||
|
||
namespace tateyama::version { | ||
|
||
constexpr std::string_view info_file_name_string = "tsurugi-info.json"; | ||
|
||
tgctl::return_code show_version(const std::string& argv0) | ||
{ | ||
auto base_path = tateyama::process::get_base_path(argv0); | ||
std::string info_file_name(info_file_name_string); | ||
auto info_file_path = base_path / boost::filesystem::path("lib") / boost::filesystem::path(info_file_name); | ||
|
||
if (boost::filesystem::exists(info_file_path) && !boost::filesystem::is_directory(info_file_path)) { | ||
boost::property_tree::ptree pt; | ||
try { | ||
boost::property_tree::read_json(info_file_path.string(), pt); | ||
|
||
auto name_opt = pt.get_optional<std::string>("name"); | ||
auto version_opt = pt.get_optional<std::string>("version"); | ||
auto date_opt = pt.get_optional<std::string>("date"); | ||
|
||
if (name_opt && version_opt && date_opt) { | ||
// name | ||
std::cout << name_opt.value() << std::endl; | ||
// version | ||
std::cout << "version: " << version_opt.value() << std::endl; | ||
// date | ||
std::cout << "date: " << date_opt.value() << std::endl; | ||
return tgctl::return_code::ok; | ||
} | ||
std::cerr << info_file_path.string() << " is incorrect" << std::endl; | ||
return tgctl::return_code::err; | ||
} catch (boost::property_tree::json_parser_error &e) { | ||
std::cerr << "parse error for " << info_file_path.string() << ":" << e.what() << std::endl; | ||
} | ||
return tgctl::return_code::err; | ||
} | ||
std::cerr << "can't find " << info_file_path.string() << std::endl; | ||
return tgctl::return_code::err; | ||
} | ||
|
||
} // namespace tateyama::version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2022-2023 tsurugi project. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include "tateyama/tgctl/tgctl.h" | ||
|
||
namespace tateyama::version { | ||
|
||
tgctl::return_code show_version(const std::string& argv0); | ||
|
||
} // tateyama::process |