protected override void EndProcessing()
        {
            base.EndProcessing();

            if (!string.IsNullOrWhiteSpace(Header) && (Body == null || !Body.Any()))
            {
                throw new PSArgumentException("Header cannot be used without Body. Please specify a Body and try again.");
            }

            var hour = Now.Time().Hour;

            if (hour is >= 0 and <= 4)
            {
                var dayPrior = Date.Minus(Period.FromDays(1));
                var question = $"Edit entry for '{dayPrior}' or '{Date}'?";
                var result   = Choice("It's after midnight!", question, 0, dayPrior.DayOfWeek.ToChoiceString(), Date.DayOfWeek.ToChoiceString());
                if (result == 0)
                {
                    Date = dayPrior;
                }
            }

            var journal = OpenJournal();

            journal.AppendEntryContent(Date, Body, Header, Tags, Readme, out var warnings);

            foreach (var warning in warnings)
            {
                WriteWarning(warning.Wrap(WrapWidth));
            }
        }
Beispiel #2
0
        protected override void RunJournalCommand()
        {
            if (!string.IsNullOrWhiteSpace(Header))
            {
                HeaderValidator.ValidateOrThrow(Header);
            }

            if (!string.IsNullOrWhiteSpace(Header) && (Body == null || !Body.Any()))
            {
                throw new PSArgumentException("Header cannot be used without Body. Please specify a Body and try again.");
            }

            var entryDate = LocalDate.FromDateTime(Date).PlusDays(DateOffset);
            var hour      = Now.Time().Hour;

            if (hour >= 0 && hour <= 4)
            {
                var dayPrior = entryDate.Minus(Period.FromDays(1));
                var question = $"Edit entry for '{dayPrior}' or '{entryDate}'?";
                var result   = Choice("It's after midnight!", question, 0, dayPrior.DayOfWeek.ToChoiceString(), entryDate.DayOfWeek.ToChoiceString());
                if (result == 0)
                {
                    entryDate = dayPrior;
                }
            }

            Commit(GitCommitType.PreAppendJournalEntry);
            var journal = OpenJournal();

            journal.AppendEntryContent(entryDate, Body, Header, Tags);
            Commit(GitCommitType.PostAppendJournalEntry);
        }
Beispiel #3
0
        protected override void EndProcessing()
        {
            base.EndProcessing();

            var journal = OpenJournal();

            var hour = Now.Time().Hour;

            if (hour >= 0 && hour <= 4)
            {
                var dayPrior = Date.Minus(Period.FromDays(1));
                var question = $"Did you mean to create an entry for '{dayPrior}' or '{Date}'?";
                var result   = Choice("It's after midnight!", question, 0, dayPrior.DayOfWeek.ToChoiceString(), Date.DayOfWeek.ToChoiceString());
                if (result == 0)
                {
                    Date = dayPrior;
                }
            }

            try
            {
                journal.CreateNewEntry(Date, Tags, Readme);
                new JournalTagCache().Invalidate();
            }
            catch (JournalEntryAlreadyExistsException e)
            {
                var question = $"An entry for {Date} already exists. Do you want to open it instead?";
                if (YesOrNo(question))
                {
                    SystemProcess.Start(e.EntryFilePath);
                }
            }
        }
        protected override void RunJournalCommand()
        {
            var journal   = OpenJournal();
            var entryDate = Date == null?Today.PlusDays(DateOffset) : LocalDate.FromDateTime(Date.Value).PlusDays(DateOffset);

            var hour = Now.Time().Hour;

            if (hour >= 0 && hour <= 4)
            {
                var dayPrior = entryDate.Minus(Period.FromDays(1));
                var question = $"Did you mean to create an entry for '{dayPrior}' or '{entryDate}'?";
                var result   = Choice("It's after midnight!", question, 0, dayPrior.DayOfWeek.ToChoiceString(), entryDate.DayOfWeek.ToChoiceString());
                if (result == 0)
                {
                    entryDate = dayPrior;
                }
            }

            Commit(GitCommitType.PreNewJournalEntry);

            try
            {
                journal.CreateNewEntry(entryDate, Tags, Readme);
                Commit(GitCommitType.PostNewJournalEntry);
            }
            catch (JournalEntryAlreadyExistsException e)
            {
                var question = $"An entry for {entryDate} already exists. Do you want to open it instead?";
                if (YesOrNo(question))
                {
                    SystemProcess.Start(e.EntryFilePath);
                }
            }
        }