protected override void RunJournalCommand() { if (Last) { var journal = OpenJournal(); var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).First(); SystemProcess.Start(lastEntry.FilePath); return; } var fileSystem = new FileSystem(); var journalWriter = new JournalWriter(fileSystem, Location); string path; LocalDate entryDate; switch (ParameterSetName) { case "Name": { entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value; path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "Date": { entryDate = LocalDate.FromDateTime(Date); path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "DateOffset": { entryDate = Today.PlusDays(DateOffset); path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "Entry": { entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value; path = journalWriter.GetJournalEntryFilePath(entryDate); break; } default: throw new NotSupportedException(); } if (!fileSystem.File.Exists(path)) { throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'."); } SystemProcess.Start(path); }
protected override void RunJournalCommand() { if (Last) { var journal = OpenJournal(); var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).FirstOrDefault(); if (lastEntry == null) { throw new PSInvalidOperationException("No entries found!"); } SystemProcess.Start(lastEntry.FilePath); return; } var fileSystem = new FileSystem(); var journalWriter = new JournalWriter(fileSystem, Location); string path; LocalDate entryDate; switch (ParameterSetName) { case "Name": { entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value; path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "Date": { entryDate = LocalDate.FromDateTime(Date); path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "DateOffset": { entryDate = Today.PlusDays(DateOffset); path = journalWriter.GetJournalEntryFilePath(entryDate); break; } case "Entry": { entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value; path = journalWriter.GetJournalEntryFilePath(entryDate); break; } default: throw new NotSupportedException(); } if (!fileSystem.File.Exists(path)) { throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'."); } Commit(GitCommitType.PreOpenJournalEntry); SystemProcess.Start(path); if (Wait) { var result = Choice($"Reading entry for {entryDate}", "Continue on to next entry?", 0, "&Continue", "&Quit"); Commit(GitCommitType.PostOpenJournalEntry); if (result == 1) { ThrowTerminatingError("Pipeline terminated at user's request.", ErrorCategory.NotSpecified); } } }