Skip to content

Commit

Permalink
fix tab completation
Browse files Browse the repository at this point in the history
  • Loading branch information
zdzhaoyong committed Oct 20, 2021
1 parent a84c704 commit 50da0fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
17 changes: 3 additions & 14 deletions cmake/tab_completion.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#. ~/.bashrc // why source not usable?
while read line
do
if [[ $line == "SVAR_COMPLETION_ENABLED=ON" ]];then
SVAR_COMPLETION_ENABLED=ON
fi
done < ~/.bashrc


if [ -z "$SVAR_COMPLETION_ENABLED" ];then
echo '
# svar tab completion support
function_svar_complete()
Expand All @@ -26,9 +16,8 @@ function_svar_complete()
complete -F function_svar_complete "svar"
SVAR_COMPLETION_ENABLED=ON
'>> ~/.bashrc
else
echo "svar tab completion has already supported."
fi
'>> /etc/bash_completion.d/svar

echo "svar tab completion is now supported by /etc/bash_completion.d/svar."


7 changes: 6 additions & 1 deletion src/Svar/Svar.h
Original file line number Diff line number Diff line change
Expand Up @@ -3441,7 +3441,9 @@ T& Svar::dump(T& o,const int indent_step,const int current_indent)const
Svar a = cls.__str__(*this);
return o<<a.as<std::string>();
}
return o<<"<"<<typeName()<<" at "<<std::to_string((long)value().get())<<">";
std::stringstream sst;
sst<<value().get();
return o<<"<"<<typeName()<<" at "<<sst.str()<<">";
}
}
}
Expand Down Expand Up @@ -4875,6 +4877,7 @@ class SvarBuiltin{
.def("__init__",&SvarBuiltin::int_create)
.def("__double__",[](int& i){return (double)i;})
.def("__bool__",[](int& i){return (bool)i;})
.def("__str__",[](int& i){return std::to_string(i);})
.def("__eq__",[](int& self,int rh){return self==rh;})
.def("__lt__",[](int& self,int rh){return self<rh;})
.def("__add__",[](int& self,Svar& rh)->Svar{
Expand Down Expand Up @@ -4908,11 +4911,13 @@ class SvarBuiltin{
SvarClass::Class<bool>()
.def("__int__",[](bool& b){return (int)b;})
.def("__double__",[](bool& b){return (double)b;})
.def("__str__",[](bool& b){return std::to_string(b);})
.def("__eq__",[](bool& self,bool& rh){return self==rh;});

SvarClass::Class<double>()
.def("__int__",[](double& d){return (int)d;})
.def("__bool__",[](double& d){return (bool)d;})
.def("__str__",[](double& d){return std::to_string(d);})
.def("__eq__",[](double& self,double rh){return self==rh;})
.def("__lt__",[](double& self,double rh){return self<rh;})
.def("__neg__",[](double& self){return -self;})
Expand Down
11 changes: 9 additions & 2 deletions src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc,char** argv){
std::stringstream sst;
sst<<"svar [app_name] [-option value] [-help]\n"
<<"The following apps can be used:\n";
var["__usage__"]=sst.str()+description.dump_json();
var["__usage__"]=sst.str()+description.dump_json(2);
return var.help();
}

Expand All @@ -38,5 +38,12 @@ int main(int argc,char** argv){
LOG(ERROR)<<unParsed.front()<<" is not a valid app";
}

return app(var).as<int>();
try{
return app(var).as<int>();
}
catch(std::exception& e){
for(int i=0;i<argc;i++)
LOG(INFO)<<argv[i];
LOG(FATAL)<<e.what();
}
}

0 comments on commit 50da0fa

Please sign in to comment.