Function parse_shebang

Source
pub fn parse_shebang<R: Read>(reader: R) -> Result<TagSet>
Expand description

Parse a shebang line from a reader and return interpreter tags.

This function reads the first line from the provided reader and parses it as a shebang line to determine the script interpreter.

§Arguments

  • reader - A reader providing the file content

§Returns

A set of tags for the interpreter found in the shebang line. Returns an empty set if no valid shebang is found.

§Examples

use file_identify::parse_shebang;
use std::io::Cursor;

let shebang = Cursor::new(b"#!/usr/bin/env python3\nprint('hello')");
let tags = parse_shebang(shebang).unwrap();
assert!(tags.contains("python"));
assert!(tags.contains("python3"));

let no_shebang = Cursor::new(b"print('hello')");
let tags = parse_shebang(no_shebang).unwrap();
assert!(tags.is_empty());