<commit_before>//
//  ls.swift
//  GeekWeather
//
//  Created by 梅俊 on 15/12/17.
//  Copyright © 2015年 RangerStudio. All rights reserved.
//

import UIKit

class ls: Command {
    
    override init(path: String) {
        super.init(path: path)
        self.validOptions = ["1", "a"]
    }
    
    enum LsCmdExecError : ErrorType{
        case DirNotFound(dir : String)
    }
    
    override internal func execute() throws -> String! {
        var results : [String] = [String]()
        for path in self.arguments {
            let relativePath = self.workPath + "/\(path)"
            var fullpath : String?
            if NSFileManager.defaultManager().fileExistsAtPath(relativePath) {
                fullpath = relativePath
            }
            else {
                let absolutePath = ShellCore.defaultShellCore.homepath + "/\(path)"
                if NSFileManager.defaultManager().fileExistsAtPath(absolutePath) {
                    fullpath = absolutePath
                } else {
                    throw LsCmdExecError.DirNotFound(dir: path)
                }
            }

            guard let _ = fullpath else {
                continue
            }
            
            var paths = try! NSFileManager.defaultManager().contentsOfDirectoryAtPath(fullpath!)
                
            var count = 3
            for option in self.options {
                switch option.option {
                case "1":
                    count = 1
                case "a":
                    paths.append(".")<commit_msg>fix bug when ls command has no argument<commit_after>//
//  ls.swift
//  GeekWeather
//
//  Created by 梅俊 on 15/12/17.
//  Copyright © 2015年 RangerStudio. All rights reserved.
//

import UIKit

class ls: Command {
    
    override init(path: String) {
        super.init(path: path)
        self.validOptions = ["1", "a"]
    }
    
    enum LsCmdExecError : ErrorType{
        case DirNotFound(dir : String)
    }
    
    override internal func execute() throws -> String! {
        var results : [String] = [String]()
        
        if self.arguments.isEmpty {
            self.arguments.append("");
        }
        
        for path in self.arguments {
            let relativePath = self.workPath + "/\(path)"
            var fullpath : String?
            if NSFileManager.defaultManager().fileExistsAtPath(relativePath) {
                fullpath = relativePath
            }
            else {
                let absolutePath = ShellCore.defaultShellCore.homepath + "/\(path)"
                if NSFileManager.defaultManager().fileExistsAtPath(absolutePath) {
                    fullpath = absolutePath
                } else {
                    throw LsCmdExecError.DirNotFound(dir: path)
                }
            }

            guard let _ = fullpath else {
                continue
            }
            
            var paths = try! NSFileManager.defaultManager().contentsOfDirectoryAtPath(fullpath!)
                
            var count = 3
            for option in self.options {
                switch option.option {
                case "1":
                    count = 1
                case "a":
                    paths.append(".")
{'fraction_non_alphanumeric': 0.0923220391669257, 'fraction_numerical': 0.008703761268262356, 'mean_word_length': 1.3679175864606328, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '3924238', 'n_tokens_mistral': 871, 'n_tokens_neox': 814, 'n_words': 203}