<commit_before>//
//  main.swift
//  The Lazy Cocoa Project
//
//  Copyright (c) 2015 <NAME>. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//

import Foundation
import Cocoa

func printUsage() {
	
	println()
	println("Usage:")
	println("\t$ lzyc COMMAND")
	println("Commands:")
	println("\t+ init    Generate a Lazyfile for the current directory.")
	println("\t+ update  Export source code files required in the Lazyfile.")
	println()
}

if ( Process.arguments.count < 2) {
	
	printUsage()
} else {
	
	let command = Process.arguments[1]
	var fileName = "Lazyfile"
	let fileManager = NSFileManager.defaultManager()
	
	switch command {
	case "init":
		
		if fileManager.fileExistsAtPath(fileName) {
			
			println("\(fileName) already exists")
		} else {
			
			var error:NSError?
			let template = LZYDataManager.lazyFileTemplate()
			template.writeToFile(fileName, atomically: true, encoding: NSUTF8StringEncoding, error: &error)
			
			if let error = error {
				println(error.localizedDescription)
			}
		}
		
		break
	case "update":
		
		if fileManager.fileExistsAtPath(fileName) {
			
			var analyzer = DocumentAnalyzer()
			analyzer.platform = Platform.iOS

			var error:NSError?
			let sourceString = NSString(contentsOfFile: fileName, encoding: NSUTF8StringEncoding, error: &error)

			if let sourceString = sourceString {
				
				analyzer.inputString = sourceString as String
				analyzer.process()
				
				for d in analyzer.sourceCodeDocuments {
					
					if d.exportTo.isEmpty == false {
						
						let exportPath = d.exportTo.stringByTrimmingWhiteSpaceAndNewLineCharacters()
						
						let fullExportPath = fileManager.currentDirectoryPath.stringByAppendingPathComponent(exportPath)
						
						d.documentString.writeToFile(fullExportPath, atomically: true, encoding: NSUTF8StringEncoding, error: &error)
						
						if let error = error {
							println("Failed to export:  \(fullExportPath)")
						} else {
							println("Exported successfully:  \(fullExportPath)")
						}
					} else {
						println("Failed to export, export path is not set")
					}
				}
			} else {
				
				println("\(fileName) can not be opened")
			}
		} else {
			
			println("\(fileName) does not exist")
		}
		break
	default:
		println("Invalid command!")
		printUsage()
		
		break
	}
	
}<commit_msg>Modified main.swift to use MainProgram<commit_after>//
//  main.swift
//  The Lazy Cocoa Project
//
//  Copyright (c) 2015 <NAME>. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//

import Foundation
import Cocoa

func printUsage() {
	
	println()
	println("Usage:")
	println("\t$ lzyc COMMAND")
	println("Commands:")
	println("\t+ init    Generate a Lazyfile for the current directory.")
	println("\t+ update  Export source code files required in the Lazyfile.")
	println()
}

if ( Process.arguments.count < 2) {
	
	printUsage()
} else {
	
	let command = Process.arguments[1]
	let prog = MainProgram()
	let fileManager = NSFileManager.defaultManager()
	var error:NSError?
	
	switch command {
	case "init":
		
		if prog.fileExistsNotDirectory(
			filePath: fileManager.currentDirectoryPath.stringByAppendingPathComponent(prog.fileName),
			error: &error
			) {
			
			println("\(prog.fileName) already exists")
		} else {
			
			var error:NSError?
			let template = LZYDataManager.lazyFileTemplate()
			template.writeToFile(prog.fileName, atomically: true, encoding: NSUTF8StringEncoding, error: &error)
			
			if let error = error {
				println(error.localizedDescription)
			}
		}
		
		break
	case "update":
		
		var analyzer = DocumentAnalyzer()
		analyzer.platform = Platform.iOS

		error = nil
		if let sourceString = prog.lazyfileString(basePath: fileManager.currentDirectoryPath, error: &error) {
			
			analyzer.inputString = sourceString as String
			analyzer.process()
			
			for d in analyzer.sourceCodeDocuments {
				
				if d.exportTo.isEmpty == false {
					
					let exportPath = d.exportTo.stringByTrimmingWhiteSpaceAndNewLineCharacters()
					
					let fullExportPath = fileManager.currentDirectoryPath.stringByAppendingPathComponent(exportPath)
					
					d.documentString.writeToFile(fullExportPath, atomically: true, encoding: NSUTF8StringEncoding, error: &error)
					
					if let error = error {
						println("Failed to export:  \(fullExportPath)")
					} else {
						println("Exported successfully:  \(fullExportPath)")
					}
				} else {
					println("Failed to export, export path is not set")
				}
			}
		} else {
			
			println(error?.localizedDescription)
		}
		
		break
	default:
		println("Invalid command!")
		printUsage()
		
		break
	}
	
}
{'fraction_non_alphanumeric': 0.09139704786044431, 'fraction_numerical': 0.0025346652750857313, 'mean_word_length': 3.37573385518591, 'pattern_counts': {'":': 4, '<': 7, '<?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': '2093210', 'n_tokens_mistral': 2264, 'n_tokens_neox': 1851, 'n_words': 664}