prt-get: if set, use $PAGER for 'cat' and 'readme'

git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1142 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
This commit is contained in:
Johannes Winkelmann 2006-04-04 20:12:42 +00:00
parent e4d5098bb0
commit 5c03d74720
4 changed files with 28 additions and 19 deletions

View File

@ -7,6 +7,7 @@
- allow to remove log files of successful builds - allow to remove log files of successful builds
- print update summary right before running the addcommand - print update summary right before running the addcommand
- print full add command and PACKAGE_DIR info when using install/update -v - print full add command and PACKAGE_DIR info when using install/update -v
- Make 'cat' and 'readme' use $PAGER if set
* 0.5.11 29.05.2005 Johannes Winkelmann * 0.5.11 29.05.2005 Johannes Winkelmann
- add --path to 'ls' - add --path to 'ls'

View File

@ -190,7 +190,7 @@ Print the path of a port
.TP .TP
.B readme <port> .B readme <port>
Print the port's README file if it exists Print the port's README file if it exists; if set, uses $PAGER
.TP .TP
.B depends <package1> [<package2> ...] .B depends <package1> [<package2> ...]
@ -339,7 +339,7 @@ Prints out a listing of the port's directory
.TP .TP
.B cat <package> [<file>] .B cat <package> [<file>]
Prints out the file to stdout. If <file> is not specified, 'Pkgfile' is used Prints out the file to stdout. If <file> is not specified, 'Pkgfile' is used. If set, uses $PAGER
.TP .TP
.B edit <package> <file> .B edit <package> <file>

View File

@ -1212,6 +1212,25 @@ void PrtGet::readme()
const Package* p = m_repo->getPackage( arg ); const Package* p = m_repo->getPackage( arg );
if ( p ) { if ( p ) {
string file = p->path() + "/" + p->name() + "/README"; string file = p->path() + "/" + p->name() + "/README";
printFile(file);
} else {
cerr << "Package '" << arg << "' not found" << endl;
m_returnValue = PG_GENERAL_ERROR;
return;
}
}
bool PrtGet::printFile(const string& file)
{
if (!File::fileExists(file)) {
return false;
}
char* pager = getenv("PAGER");
if (pager) {
Process proc(pager, file);
proc.executeShell();
} else {
FILE* fp = fopen( file.c_str(), "r" ); FILE* fp = fopen( file.c_str(), "r" );
char buf[255]; char buf[255];
if ( fp ) { if ( fp ) {
@ -1220,14 +1239,10 @@ void PrtGet::readme()
} }
fclose( fp ); fclose( fp );
} }
} else {
cerr << "Package '" << arg << "' not found" << endl;
m_returnValue = PG_GENERAL_ERROR;
return;
}
} }
return true;
}
void PrtGet::printDependendent() void PrtGet::printDependendent()
{ {
@ -1623,19 +1638,11 @@ void PrtGet::cat()
fileName = *it; fileName = *it;
} }
string file = p->path() + "/" + p->name() + "/" + fileName; string file = p->path() + "/" + p->name() + "/" + fileName;
FILE* fp = fopen( file.c_str(), "r" ); if (!printFile(file)) {
char buf[255];
if ( fp ) {
while ( fgets( buf, 255, fp ) ) {
cout << buf;
}
fclose( fp );
} else {
cerr << "File '" << *it << "' not found" << endl; cerr << "File '" << *it << "' not found" << endl;
m_returnValue = PG_GENERAL_ERROR; m_returnValue = PG_GENERAL_ERROR;
return; return;
} }
} else { } else {
cerr << "Package '" << arg << "' not found" << endl; cerr << "Package '" << arg << "' not found" << endl;
m_returnValue = PG_GENERAL_ERROR; m_returnValue = PG_GENERAL_ERROR;

View File

@ -143,6 +143,7 @@ protected:
void assertExactArgCount(int count); void assertExactArgCount(int count);
void argCountFailure(int count, const string& specifier); void argCountFailure(int count, const string& specifier);
static bool printFile(const string& file);
}; };
#endif /* _PRTGET_H_ */ #endif /* _PRTGET_H_ */