1 /* 2 * hunt-console eases the creation of beautiful and testable command line interfaces. 3 * 4 * Copyright (C) 2018-2019, HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.console.question.Question; 13 14 import hunt.console.error.InvalidArgumentException; 15 16 class Question 17 { 18 private string question; 19 private int attempts; 20 private bool hidden = false; 21 private bool hiddenFallback = true; 22 private string defaultValue; 23 24 public this(string question) 25 { 26 this(question, null); 27 } 28 29 public this(string question, string defaultValue) 30 { 31 this.question = question; 32 this.defaultValue = defaultValue; 33 } 34 35 public string getQuestion() 36 { 37 return question; 38 } 39 40 public string getDefaultValue() 41 { 42 return defaultValue; 43 } 44 45 public bool isHidden() 46 { 47 return hidden; 48 } 49 50 public Question setHidden(bool hidden) 51 { 52 this.hidden = hidden; 53 54 return this; 55 } 56 57 public bool isHiddenFallback() 58 { 59 return hiddenFallback; 60 } 61 62 public Question setHiddenFallback(bool hiddenFallback) 63 { 64 this.hiddenFallback = hiddenFallback; 65 66 return this; 67 } 68 69 public Question setMaxAttempts(int attempts) 70 { 71 if (attempts != int.init && attempts < 1) { 72 throw new InvalidArgumentException("Maximum number of attempts must be a positive value."); 73 } 74 75 this.attempts = attempts; 76 77 return this; 78 } 79 80 public int getMaxAttempts() 81 { 82 return attempts; 83 } 84 }