【问题标题】:Ammonite scripts - load/execute script relative to root or user homeAmmonite 脚本 - 加载/执行相对于 root 或用户主目录的脚本
【发布时间】:2017-01-19 20:09:37
【问题描述】:

我正在尽量减少必须在 ammonite 脚本中编写的样板数量。似乎 predef.sc 默认没有加载(这很好),但我想为不同的文件设置不同的 predef 集,只需写一行来加载它们。

如果不导入ammonite-shell,似乎无法引用/$HOME(这反过来又要求您使用import $ivy/interp.load.ivy,这意味着总共至少有3-4行) .使用相对路径 ($file.^.somefolder.somefile) 可以,但相对路径太容易中断。

所以问题是——是否有一个单行来加载相对于root$HOME 的脚本?像

$exec $file.`$HOME`.path.to.somefile

【问题讨论】:

    标签: scala shell ammonite


    【解决方案1】:

    我认为import $exec.filerepl.load.exec 相同,因此您可以执行以下操作:

    repl.load.exec(Path("/abs/path/to/file.sc"))
    

    【讨论】:

    • 您的答案中的“repl”是什么。它似乎不是可以在菊石中导入的包或对象。 ammonite.repl 没有load 子包等
    • @ely 'repl' 是 Ammonite 中默认可用的对象。您可以从此处的文档中看到“repl.history”、“repl.width”等的用法:ammonite.io/#ReplAPI。 'repl.load' 命令也可以在这个页面上找到。
    • 当我在菊石中尝试repl.load 时出现错误:cmd1.sc:1: value load is not a member of ammonite.repl.FullReplAPI(使用版本 0.8.2)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多