Update for console_progress version, extract CLI constants.
This commit is contained in:
		
							
								
								
									
										63
									
								
								src/main/nim/cliconstants.nim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/main/nim/cliconstants.nim
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					const VERSION* = "1.4.6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const USAGE* = """
 | 
				
			||||||
 | 
					Usage:
 | 
				
			||||||
 | 
					  treediff <left> [<right>] [options]
 | 
				
			||||||
 | 
					  treediff (-h | --help)
 | 
				
			||||||
 | 
					  treediff (-V | --version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <left> and <right> represent paths to directory roots to be compared. If one
 | 
				
			||||||
 | 
					  of these paths points to a file instead of a directory, treediff assumes that
 | 
				
			||||||
 | 
					  the file represents a saved directory analysis to be loaded in place of a
 | 
				
			||||||
 | 
					  directory to compare. For example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      treediff /path/to/dir /path/to/output.json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  will analyze the directory tree at '/path/to/dir' to create the left-side
 | 
				
			||||||
 | 
					  analysis and load a pre-existing analysis from '/path/to/output.json' as the
 | 
				
			||||||
 | 
					  right-side analysis.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Options:
 | 
				
			||||||
 | 
					  -h --help       Show this usage information.
 | 
				
			||||||
 | 
					  -V --version    Show the program version.
 | 
				
			||||||
 | 
					  -v --verbose    Enable verbose output.
 | 
				
			||||||
 | 
					  -q --quiet      Suppress all output and error messages except for the
 | 
				
			||||||
 | 
					                  progress indicator.
 | 
				
			||||||
 | 
					  -Q --very-quiet Suppress all output and error messages includeing the
 | 
				
			||||||
 | 
					                  progress indicator.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -1 --save-left <left_out>   Save the left analysis to <left_out> (will be
 | 
				
			||||||
 | 
					                              formatted as JSON)
 | 
				
			||||||
 | 
					  -2 --save-right <right_out> Save the right analysis to <right_out> (will be
 | 
				
			||||||
 | 
					                              formatted as JSON)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -s --same
 | 
				
			||||||
 | 
					  -S --exclude-same
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Show or hide information about files which are the same in both trees.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -c --content-mismatch
 | 
				
			||||||
 | 
					  -C --exclude-content-mismatch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Show or hide information about files whose relative paths are the same
 | 
				
			||||||
 | 
					      in both trees but whose contents differ.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -p --path-mismatch
 | 
				
			||||||
 | 
					  -P --exclude-path-mismatch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Show or hide information about files whose contents are the same in both
 | 
				
			||||||
 | 
					      trees but whose relative paths differ.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -l --left-only
 | 
				
			||||||
 | 
					  -L --exclude-left-only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Show or hide information about files which are found only in the left
 | 
				
			||||||
 | 
					      tree.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -r --right-only
 | 
				
			||||||
 | 
					  -R --exclude-right-only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Show or hide information about files which are found only in the right
 | 
				
			||||||
 | 
					      tree.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
@@ -18,7 +18,7 @@ proc fileToMD5*(filename: string) : string =
 | 
				
			|||||||
    buffer = fs.readStr(blockSize)
 | 
					    buffer = fs.readStr(blockSize)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while buffer.len > 0:
 | 
					    while buffer.len > 0:
 | 
				
			||||||
      md5Update(c, buffer, buffer.len)
 | 
					      md5Update(c, buffer.cstring, buffer.len)
 | 
				
			||||||
      buffer = fs.readStr(blockSize)
 | 
					      buffer = fs.readStr(blockSize)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    md5Final(c, d)
 | 
					    md5Final(c, d)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@
 | 
				
			|||||||
import os, tables, streams, sequtils, strutils, docopt, marshal
 | 
					import os, tables, streams, sequtils, strutils, docopt, marshal
 | 
				
			||||||
import incremental_md5, console_progress
 | 
					import incremental_md5, console_progress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ./cliconstants
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type
 | 
					type
 | 
				
			||||||
@@ -20,7 +21,7 @@ type
 | 
				
			|||||||
proc newProgressWrapper*(outFile = stdout, verbosity = normal): ProgressWrapper =
 | 
					proc newProgressWrapper*(outFile = stdout, verbosity = normal): ProgressWrapper =
 | 
				
			||||||
  ## Create a new ProgressWrapper for the given verbosity.
 | 
					  ## Create a new ProgressWrapper for the given verbosity.
 | 
				
			||||||
  if verbosity > very_quiet:
 | 
					  if verbosity > very_quiet:
 | 
				
			||||||
    result = (impl: newProgress(outFile, 0), verbosity: verbosity)
 | 
					    result = (impl: newProgress(0, outFile), verbosity: verbosity)
 | 
				
			||||||
  else: result = (impl: nil, verbosity: verbosity)
 | 
					  else: result = (impl: nil, verbosity: verbosity)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proc init(p: ProgressWrapper, root: string, fileCount: int): void =
 | 
					proc init(p: ProgressWrapper, root: string, fileCount: int): void =
 | 
				
			||||||
@@ -170,69 +171,7 @@ when isMainModule:
 | 
				
			|||||||
    stderr.writeLine("treediff: " & error)
 | 
					    stderr.writeLine("treediff: " & error)
 | 
				
			||||||
    quit(QuitFailure)
 | 
					    quit(QuitFailure)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let doc = """
 | 
					  let args = docopt(USAGE, version = "treediff " & VERSION)
 | 
				
			||||||
Usage:
 | 
					 | 
				
			||||||
  treediff <left> [<right>] [options]
 | 
					 | 
				
			||||||
  treediff (-h | --help)
 | 
					 | 
				
			||||||
  treediff (-V | --version)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <left> and <right> represent paths to directory roots to be compared. If one
 | 
					 | 
				
			||||||
  of these paths points to a file instead of a directory, treediff assumes that
 | 
					 | 
				
			||||||
  the file represents a saved directory analysis to be loaded in place of a
 | 
					 | 
				
			||||||
  directory to compare. For example:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      treediff /path/to/dir /path/to/output.json
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  will analyze the directory tree at '/path/to/dir' to create the left-side
 | 
					 | 
				
			||||||
  analysis and load a pre-existing analysis from '/path/to/output.json' as the
 | 
					 | 
				
			||||||
  right-side analysis.
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
Options:
 | 
					 | 
				
			||||||
  -h --help       Show this usage information.
 | 
					 | 
				
			||||||
  -V --version    Show the program version.
 | 
					 | 
				
			||||||
  -v --verbose    Enable verbose output.
 | 
					 | 
				
			||||||
  -q --quiet      Suppress all output and error messages except for the
 | 
					 | 
				
			||||||
                  progress indicator.
 | 
					 | 
				
			||||||
  -Q --very-quiet Suppress all output and error messages includeing the
 | 
					 | 
				
			||||||
                  progress indicator.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -1 --save-left <left_out>   Save the left analysis to <left_out> (will be
 | 
					 | 
				
			||||||
                              formatted as JSON)
 | 
					 | 
				
			||||||
  -2 --save-right <right_out> Save the right analysis to <right_out> (will be
 | 
					 | 
				
			||||||
                              formatted as JSON)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -s --same
 | 
					 | 
				
			||||||
  -S --exclude-same
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      Show or hide information about files which are the same in both trees.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -c --content-mismatch   
 | 
					 | 
				
			||||||
  -C --exclude-content-mismatch
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      Show or hide information about files whose relative paths are the same
 | 
					 | 
				
			||||||
      in both trees but whose contents differ.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -p --path-mismatch
 | 
					 | 
				
			||||||
  -P --exclude-path-mismatch
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      Show or hide information about files whose contents are the same in both
 | 
					 | 
				
			||||||
      trees but whose relative paths differ.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -l --left-only
 | 
					 | 
				
			||||||
  -L --exclude-left-only
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      Show or hide information about files which are found only in the left
 | 
					 | 
				
			||||||
      tree.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  -r --right-only
 | 
					 | 
				
			||||||
  -R --exclude-right-only
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      Show or hide information about files which are found only in the right
 | 
					 | 
				
			||||||
      tree.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let args = docopt(doc, version = "treediff v1.4.5")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var verbosity = normal
 | 
					  var verbosity = normal
 | 
				
			||||||
  if args["--quiet"]: verbosity = quiet
 | 
					  if args["--quiet"]: verbosity = quiet
 | 
				
			||||||
@@ -320,4 +259,3 @@ Options:
 | 
				
			|||||||
    if displayOptions.right:
 | 
					    if displayOptions.right:
 | 
				
			||||||
      let rightOnly = rightAnalysis - leftAnalysis
 | 
					      let rightOnly = rightAnalysis - leftAnalysis
 | 
				
			||||||
      for fe in rightOnly: echo "right only: ", fe.relPath
 | 
					      for fe in rightOnly: echo "right only: ", fe.relPath
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
# Package
 | 
					# Package
 | 
				
			||||||
version       = "1.4.5"
 | 
					version       = "1.4.6"
 | 
				
			||||||
author        = "Jonathan Bernard (jdb@jdb-labs.com)"
 | 
					author        = "Jonathan Bernard (jdb@jdb-labs.com)"
 | 
				
			||||||
description   = "Utility to generate diffs of full directory trees."
 | 
					description   = "Utility to generate diffs of full directory trees."
 | 
				
			||||||
license       = "BSD"
 | 
					license       = "BSD"
 | 
				
			||||||
@@ -7,4 +7,11 @@ bin           = @["treediff"]
 | 
				
			|||||||
srcDir        = "src/main/nim"
 | 
					srcDir        = "src/main/nim"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Dependencies
 | 
					# Dependencies
 | 
				
			||||||
requires: @["nim >= 1.0.4", "docopt >= 0.6.8", "console_progress >= 1.2.1"]
 | 
					requires: @["nim >= 1.0.4", "docopt >= 0.6.8"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Dependencies from git.jdb-software.com/jdb/nim-packages
 | 
				
			||||||
 | 
					requires: @["console_progress >= 1.2.2"]
 | 
				
			||||||
 | 
					requires "https://git.jdb-software.com/jdb/update-nim-package-version.git"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					task updateVersion, "Update the version of this package.":
 | 
				
			||||||
 | 
					  exec "update_nim_package_version treediff 'src/main/nim/cliconstants.nim'"
 | 
				
			||||||
		Reference in New Issue
	
	Block a user