<commit_before>##
# Rust cargo Project.
##
module IBuild::Projects
  class Cargo < Project
    BUILD_FILE = "Cargo.toml"
    def self.detect(dir)
      pclj = dir + "/#{BUILD_FILE}"
      File.exists?(pclj)
    end

    def info(): ProjectInfo
      lines = File.read(BUILD_FILE).lines
      ProjectInfo.new str_value("name", lines), str_value("version", lines)
    end

    private def str_value(key, lines)
      line = lines.find {|x| x.starts_with?(key) }
      if line
         line = line.strip
         start = line.index("\"")
         line[(start+1)..-2] if start
      end
    end

    def compile()
      sh "cargo build"
    end

    # @Override
    def run()
      sh "cargo run"
    end

    # @Override
    def test()
      sh "cargo test"
    end

    # @Override
    def repl()
      super
    end

    # @Override
    def format()
      sh "cargo do fmt"
    end

    def clean()
      sh "cargo clean"
    end

    def deps_tree()
      super
    end

    def deps_outdated()
      super
    end
<commit_msg>add deps:tree support for cargo<commit_after>##
# Rust cargo Project.
##
module IBuild::Projects
  class Cargo < Project
    BUILD_FILE = "Cargo.toml"
    def self.detect(dir)
      pclj = dir + "/#{BUILD_FILE}"
      File.exists?(pclj)
    end

    def info(): ProjectInfo
      lines = File.read(BUILD_FILE).lines
      ProjectInfo.new str_value("name", lines), str_value("version", lines)
    end

    private def str_value(key, lines)
      line = lines.find {|x| x.starts_with?(key) }
      if line
         line = line.strip
         start = line.index("\"")
         line[(start+1)..-2] if start
      end
    end

    def compile()
      sh "cargo build"
    end

    # @Override
    def run()
      sh "cargo run"
    end

    # @Override
    def test()
      sh "cargo test"
    end

    # @Override
    def repl()
      super
    end

    # @Override
    def format()
      # @see https://github.com/pwoolcoc/cargo-fmt
      # @see https://github.com/pwoolcoc/cargo-do
      sh "cargo do fmt"
    end

    def clean()
      sh "cargo clean"
    end

    def deps_tree()
      # @see https://github.com/killercup/cargo-edit
      sh "cargo do list --tree"
    end

    def deps_outdated()
      super
    end

{'fraction_non_alphanumeric': 0.11754229741763135, 'fraction_numerical': 0.0017809439002671415, 'mean_word_length': 1.8734015345268542, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638900', 'n_tokens_mistral': 781, 'n_tokens_neox': 760, 'n_words': 204}