From 7136b3cc3ea81fe30961a2d9455feeba22f39fa9 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Sun, 9 Apr 2017 21:26:11 -0700 Subject: [PATCH] activate now uses output funcs, create_symlink wrapped in a try/catch --- src/bottles/activate.cpp | 14 ++++++++++---- src/bottles/remove.cpp | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bottles/activate.cpp b/src/bottles/activate.cpp index ef5033f..c522966 100644 --- a/src/bottles/activate.cpp +++ b/src/bottles/activate.cpp @@ -8,13 +8,14 @@ #include "bottles.hpp" #include "internal/bottles.hpp" +#include "output.hpp" using namespace std; using namespace boost::filesystem; void cellar::bottles::switch_active_bottle(int argc, vector argv) { if (argc == 1) { - cout << "forgot to specify a bottle to activate" << endl; + output::error("forgot to specify a bottle to activate"); return; } @@ -24,7 +25,7 @@ void cellar::bottles::switch_active_bottle(int argc, vector argv) { file_status targetstatus = symlink_status(targetpath); if (!exists(targetstatus)) { - cerr << "target " << targetpath << " does not exist" << endl; + output::error("target " + targetpath + " does not exist"); return; } @@ -32,12 +33,17 @@ void cellar::bottles::switch_active_bottle(int argc, vector argv) { if (exists(bottlestatus)) { bool bottlesymlink = is_symlink(bottlestatus); if (!bottlesymlink) { - cerr << "refusing to clobber " << bottlepath << ": not a symlink" << endl; + output::error("refusing to clobber " + bottlepath + ": not a symlink"); return; } remove(bottlepath); } // 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; + } } diff --git a/src/bottles/remove.cpp b/src/bottles/remove.cpp index 5989348..9d1c6d5 100644 --- a/src/bottles/remove.cpp +++ b/src/bottles/remove.cpp @@ -19,7 +19,7 @@ void cellar::bottles::remove_bottle(int argc, vector argv) { string fullbottlepath; if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == "." || bottlechoice.substr(0,1) == "~") { // absolute or relative path output::error("paths not accepted"); - return 1; + return; } else { if (bottlechoice.substr(0,6) == ".wine.") { output::statement("tip: cellar can add the \".wine.\" prefix automatically");