Skip to content

Add an option to specify the output directory - #104

Merged
pkgw merged 8 commits into
tectonic-typesetting:masterfrom
h4llow3En:master
Jun 21, 2017
Merged

Add an option to specify the output directory#104
pkgw merged 8 commits into
tectonic-typesetting:masterfrom
h4llow3En:master

Conversation

@h4llow3En

Copy link
Copy Markdown
Contributor

This closes #96.

@h4llow3En h4llow3En changed the title Add an option to specify the output directory WIP: Add an option to specify the output directory Jun 16, 2017
@h4llow3En h4llow3En changed the title WIP: Add an option to specify the output directory Add an option to specify the output directory Jun 16, 2017
Comment thread src/cli_driver.rs Outdated
let tmp = PathBuf::from(dir);
match tmp.extension() {
Some(_) => {
tt_warning!(status, "file extention in outdir; only the directory will be used");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extention => extension
Maybe also outdir => `-o/--outdir`, so it's clear that outdir means the command line option?

Comment thread src/cli_driver.rs Outdated
/// dirname of `primary_input_path`, or an empty path (i.e., corresponding
/// to the CWD if `primary_input_path` is None.
fs_root: PathBuf,
#[allow(unused)] fs_root: PathBuf,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is #[allow(unused)] necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this in because now it is unused. But maybe it will be needed later?
Else there would be a warning while compiling.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, I misunderstood, I thought the fs_root below is this one. I think that it is better to remove it. It's easy to add it back if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will do this

Comment thread src/cli_driver.rs Outdated
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.to_string_lossy())).into());}
} else {
output_path = fs_root.clone().to_path_buf()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a double clone? Just clone() seems enough.

@h4llow3En h4llow3En Jun 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just clone() returns a &Path which is mismatched with PathBuf. Even if it should be equal because *PathBuf is a Path

Comment thread src/cli_driver.rs Outdated
}
None => tmp,
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.to_string_lossy())).into());}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_string_lossy => display

Comment thread src/cli_driver.rs Outdated

let mut real_path = self.fs_root.clone();
let mut real_path = self.output_path.clone();
real_path.push(name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written as

let real_path = self.output_path.join(name);

Comment thread tests/executable.rs Outdated
let tempdir = setup_and_copy_files(&["subdirectory/content/1.tex"]);

let output = run_tectonic(tempdir.path(),
&["--format=plain.fmt.gz", "subdirectory/content/1.tex", "--outdir=subdirectory/non_existant"]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non_existant => non_existent

Comment thread src/cli_driver.rs Outdated
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.display())).into());}
} else {
output_path = fs_root.clone().to_path_buf()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, fs_root is Path. In that case, fs_root.to_path_buf() (or fs_root.to_owned()) should do.

@pkgw pkgw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me so long to get to this! Thanks, looks good — I just have a few small stylistic requests.

Comment thread src/cli_driver.rs Outdated
}

if let Some(dir) = args.value_of("outdir") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

Comment thread src/cli_driver.rs Outdated
}
None => &tmp,
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.display())).into());}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't condense the bodies of if statements to single lines. That is, please put the return statement and closing bracket on their own lines.

Comment thread src/cli_driver.rs Outdated
.long("outdir")
.short("o")
.value_name("OUTDIR")
.help("The output directory. Default: Same like INPUT."))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the default description as it appears in the other arguments; something like

The directory in which to place output files. [default: the directory containing INPUT]

@h4llow3En

Copy link
Copy Markdown
Contributor Author

As you wished, I cleaned up the Code

@pkgw pkgw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi — I was looking over this PR again and I noticed a few more things in the handling of the argument that I think should be changed a bit. They're subtle but I think they're important for providing consistent behavior for the user. Can you please make these tweaks too? Thanks for taking the time to work through the process!

Comment thread src/cli_driver.rs Outdated
}
}

if let Some(dir) = args.value_of("outdir") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use value_of_os to get an OsString from the argument.

Comment thread src/cli_driver.rs Outdated
if let Some(dir) = args.value_of("outdir") {
output_path = {
let tmp = Path::new(dir);
match tmp.extension() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code should special-case the circumstance where the argument path has an extension. It's not common but sometimes directory names have extensions like files, and in those cases you'll get surprising behavior because the program will alter the path that you pass it.

Comment thread src/cli_driver.rs Outdated
None => &tmp,
}
};
if !output_path.exists() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, I think here the check should use is_dir, not exists. I think this is closer to what we want and it will handle the case where the user inadvertently passes a filename instead of a directory name to the -o option.

@h4llow3En

Copy link
Copy Markdown
Contributor Author

I applied you change requests. Could you rerun the one failed test, please?

@pkgw

pkgw commented Jun 21, 2017

Copy link
Copy Markdown
Collaborator

Transient test failure resolved. Thanks!

@pkgw
pkgw merged commit 6761ceb into tectonic-typesetting:master Jun 21, 2017
Mrmaxmeier pushed a commit to Mrmaxmeier/tectonic that referenced this pull request Oct 1, 2019
use objc crate's msg_send! macro to replace placeholders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify output path

3 participants