mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
ln: Make the 'path' argument optional
If 'path' is omitted, we create a link with the basename of whatever the target is. This matches what other systems do.
This commit is contained in:
parent
3d7b8de64f
commit
56701f91f9
1 changed files with 8 additions and 1 deletions
|
@ -24,6 +24,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -44,9 +45,15 @@ int main(int argc, char** argv)
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(symbolic, "Create a symlink", "symbolic", 's');
|
args_parser.add_option(symbolic, "Create a symlink", "symbolic", 's');
|
||||||
args_parser.add_positional_argument(target, "Link target", "target");
|
args_parser.add_positional_argument(target, "Link target", "target");
|
||||||
args_parser.add_positional_argument(path, "Link path", "path");
|
args_parser.add_positional_argument(path, "Link path", "path", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
String path_buffer;
|
||||||
|
if (!path) {
|
||||||
|
path_buffer = LexicalPath(target).basename();
|
||||||
|
path = path_buffer.characters();
|
||||||
|
}
|
||||||
|
|
||||||
if (symbolic) {
|
if (symbolic) {
|
||||||
int rc = symlink(target, path);
|
int rc = symlink(target, path);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue