activate now uses output funcs, create_symlink wrapped in a try/catch

This commit is contained in:
Nicholas O'Connor 2017-04-09 21:26:11 -07:00
parent fa731102ff
commit 7136b3cc3e
2 changed files with 11 additions and 5 deletions

View File

@ -8,13 +8,14 @@
#include "bottles.hpp" #include "bottles.hpp"
#include "internal/bottles.hpp" #include "internal/bottles.hpp"
#include "output.hpp"
using namespace std; using namespace std;
using namespace boost::filesystem; using namespace boost::filesystem;
void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) { void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) {
if (argc == 1) { if (argc == 1) {
cout << "forgot to specify a bottle to activate" << endl; output::error("forgot to specify a bottle to activate");
return; return;
} }
@ -24,7 +25,7 @@ void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) {
file_status targetstatus = symlink_status(targetpath); file_status targetstatus = symlink_status(targetpath);
if (!exists(targetstatus)) { if (!exists(targetstatus)) {
cerr << "target " << targetpath << " does not exist" << endl; output::error("target " + targetpath + " does not exist");
return; return;
} }
@ -32,12 +33,17 @@ void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) {
if (exists(bottlestatus)) { if (exists(bottlestatus)) {
bool bottlesymlink = is_symlink(bottlestatus); bool bottlesymlink = is_symlink(bottlestatus);
if (!bottlesymlink) { if (!bottlesymlink) {
cerr << "refusing to clobber " << bottlepath << ": not a symlink" << endl; output::error("refusing to clobber " + bottlepath + ": not a symlink");
return; return;
} }
remove(bottlepath); remove(bottlepath);
} }
// TODO: not blindly assume this will magically work // TODO: not blindly assume this will magically work
create_symlink(targetpath, bottlepath); try {
create_symlink(targetpath, bottlepath);
} catch (filesystem_error &exc) {
output::error(exc.what());
return;
}
} }

View File

@ -19,7 +19,7 @@ void cellar::bottles::remove_bottle(int argc, vector<string> argv) {
string fullbottlepath; string fullbottlepath;
if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == "." || bottlechoice.substr(0,1) == "~") { // absolute or relative path if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == "." || bottlechoice.substr(0,1) == "~") { // absolute or relative path
output::error("paths not accepted"); output::error("paths not accepted");
return 1; return;
} else { } else {
if (bottlechoice.substr(0,6) == ".wine.") { if (bottlechoice.substr(0,6) == ".wine.") {
output::statement("tip: cellar can add the \".wine.\" prefix automatically"); output::statement("tip: cellar can add the \".wine.\" prefix automatically");